@@ -170,8 +170,9 @@ fn render_json_output(
170170
171171/// Print a view of the resources in a codec.
172172pub fn print_view ( codec : & Codec , lang_filter : & Option < String > , opts : & ViewOptions ) {
173- let keys_only_text = opts. keys_only && !opts. json ;
174- if !keys_only_text && !opts. json {
173+ let text_mode = !opts. json ;
174+ let keys_only_text = opts. keys_only && text_mode;
175+ if text_mode && !keys_only_text {
175176 println ! ( "Processing resources..." ) ;
176177 }
177178 let status_filter = match parse_status_filter ( & opts. status ) {
@@ -216,10 +217,6 @@ pub fn print_view(codec: &Codec, lang_filter: &Option<String>, opts: &ViewOption
216217 std:: process:: exit ( 1 ) ;
217218 }
218219
219- if !keys_only_text && !opts. json {
220- println ! ( "✅ Found {} resource(s)" , resources. len( ) ) ;
221- }
222-
223220 let filtered_resources = resources
224221 . iter ( )
225222 . map ( |resource| {
@@ -236,8 +233,21 @@ pub fn print_view(codec: &Codec, lang_filter: &Option<String>, opts: &ViewOption
236233 } )
237234 . collect :: < Vec < _ > > ( ) ;
238235
236+ let visible_resources = if status_filter. is_some ( ) {
237+ filtered_resources
238+ . into_iter ( )
239+ . filter ( |( _, entries) | !entries. is_empty ( ) )
240+ . collect :: < Vec < _ > > ( )
241+ } else {
242+ filtered_resources
243+ } ;
244+
245+ if text_mode && !keys_only_text {
246+ println ! ( "✅ Found {} resource(s)" , visible_resources. len( ) ) ;
247+ }
248+
239249 if opts. json {
240- let rendered = match render_json_output ( & filtered_resources , opts. keys_only ) {
250+ let rendered = match render_json_output ( & visible_resources , opts. keys_only ) {
241251 Ok ( text) => text,
242252 Err ( err) => {
243253 eprintln ! ( "❌ {}" , err) ;
@@ -250,7 +260,7 @@ pub fn print_view(codec: &Codec, lang_filter: &Option<String>, opts: &ViewOption
250260
251261 if keys_only_text {
252262 let include_lang_prefix = lang_filter. is_none ( ) ;
253- for ( resource, entries) in & filtered_resources {
263+ for ( resource, entries) in & visible_resources {
254264 for entry in entries {
255265 if include_lang_prefix {
256266 println ! ( "{}\t {}" , resource. metadata. language, entry. id) ;
@@ -262,7 +272,7 @@ pub fn print_view(codec: &Codec, lang_filter: &Option<String>, opts: &ViewOption
262272 return ;
263273 }
264274
265- for ( i, ( resource, entries) ) in filtered_resources . iter ( ) . enumerate ( ) {
275+ for ( i, ( resource, entries) ) in visible_resources . iter ( ) . enumerate ( ) {
266276 println ! ( "\n === Resource {} ===" , i + 1 ) ;
267277 println ! ( "Language: {}" , resource. metadata. language) ;
268278 println ! ( "Domain: {}" , resource. metadata. domain) ;
@@ -309,7 +319,7 @@ pub fn print_view(codec: &Codec, lang_filter: &Option<String>, opts: &ViewOption
309319 if lang_filter. is_none ( ) {
310320 let mut unique_keys = HashSet :: new ( ) ;
311321 let mut per_language_counts: BTreeMap < String , usize > = BTreeMap :: new ( ) ;
312- for ( resource, entries) in & filtered_resources {
322+ for ( resource, entries) in & visible_resources {
313323 per_language_counts
314324 . entry ( resource. metadata . language . clone ( ) )
315325 . and_modify ( |count| * count += entries. len ( ) )
0 commit comments