1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- use crate :: args:: { ConfigSubCommand , DscType , ExtensionSubCommand , OutputFormat , ResourceSubCommand } ;
4
+ use crate :: args:: { ConfigSubCommand , DscType , ExtensionSubCommand , ListOutputFormat , OutputFormat , ResourceSubCommand } ;
5
5
use crate :: resolve:: { get_contents, Include } ;
6
6
use crate :: resource_command:: { get_resource, self } ;
7
7
use crate :: tablewriter:: Table ;
@@ -611,7 +611,7 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
611
611
}
612
612
}
613
613
614
- fn list_extensions ( dsc : & mut DscManager , extension_name : Option < & String > , format : Option < & OutputFormat > , progress_format : ProgressFormat ) {
614
+ fn list_extensions ( dsc : & mut DscManager , extension_name : Option < & String > , format : Option < & ListOutputFormat > , progress_format : ProgressFormat ) {
615
615
let mut write_table = false ;
616
616
let mut table = Table :: new ( & [
617
617
t ! ( "subcommand.tableHeader_type" ) . to_string ( ) . as_ref ( ) ,
@@ -654,7 +654,13 @@ fn list_extensions(dsc: &mut DscManager, extension_name: Option<&String>, format
654
654
exit ( EXIT_JSON_ERROR ) ;
655
655
}
656
656
} ;
657
- write_object ( & json, format, include_separator) ;
657
+ let format = match format {
658
+ Some ( ListOutputFormat :: Json ) => Some ( OutputFormat :: Json ) ,
659
+ Some ( ListOutputFormat :: PrettyJson ) => Some ( OutputFormat :: PrettyJson ) ,
660
+ Some ( ListOutputFormat :: Yaml ) => Some ( OutputFormat :: Yaml ) ,
661
+ _ => None ,
662
+ } ;
663
+ write_object ( & json, format. as_ref ( ) , include_separator) ;
658
664
include_separator = true ;
659
665
// insert newline separating instances if writing to console
660
666
if io:: stdout ( ) . is_terminal ( ) { println ! ( ) ; }
@@ -663,11 +669,12 @@ fn list_extensions(dsc: &mut DscManager, extension_name: Option<&String>, format
663
669
}
664
670
665
671
if write_table {
666
- table. print ( ) ;
672
+ let truncate = format != Some ( & ListOutputFormat :: TableNoTruncate ) ;
673
+ table. print ( truncate) ;
667
674
}
668
675
}
669
676
670
- fn list_resources ( dsc : & mut DscManager , resource_name : Option < & String > , adapter_name : Option < & String > , description : Option < & String > , tags : Option < & Vec < String > > , format : Option < & OutputFormat > , progress_format : ProgressFormat ) {
677
+ fn list_resources ( dsc : & mut DscManager , resource_name : Option < & String > , adapter_name : Option < & String > , description : Option < & String > , tags : Option < & Vec < String > > , format : Option < & ListOutputFormat > , progress_format : ProgressFormat ) {
671
678
let mut write_table = false ;
672
679
let mut table = Table :: new ( & [
673
680
t ! ( "subcommand.tableHeader_type" ) . to_string ( ) . as_ref ( ) ,
@@ -677,7 +684,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
677
684
t ! ( "subcommand.tableHeader_adapter" ) . to_string ( ) . as_ref ( ) ,
678
685
t ! ( "subcommand.tableHeader_description" ) . to_string ( ) . as_ref ( ) ,
679
686
] ) ;
680
- if format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
687
+ if format == Some ( & ListOutputFormat :: TableNoTruncate ) || ( format . is_none ( ) && io:: stdout ( ) . is_terminal ( ) ) {
681
688
// write as table if format is not specified and interactive
682
689
write_table = true ;
683
690
}
@@ -759,7 +766,13 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
759
766
exit ( EXIT_JSON_ERROR ) ;
760
767
}
761
768
} ;
762
- write_object ( & json, format, include_separator) ;
769
+ let format = match format {
770
+ Some ( ListOutputFormat :: Json ) => Some ( OutputFormat :: Json ) ,
771
+ Some ( ListOutputFormat :: PrettyJson ) => Some ( OutputFormat :: PrettyJson ) ,
772
+ Some ( ListOutputFormat :: Yaml ) => Some ( OutputFormat :: Yaml ) ,
773
+ _ => None ,
774
+ } ;
775
+ write_object ( & json, format. as_ref ( ) , include_separator) ;
763
776
include_separator = true ;
764
777
// insert newline separating instances if writing to console
765
778
if io:: stdout ( ) . is_terminal ( ) { println ! ( ) ; }
@@ -768,6 +781,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
768
781
}
769
782
770
783
if write_table {
771
- table. print ( ) ;
784
+ let truncate = format != Some ( & ListOutputFormat :: TableNoTruncate ) ;
785
+ table. print ( truncate) ;
772
786
}
773
787
}
0 commit comments