11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- use crate :: args:: { ConfigSubCommand , DscType , ExtensionSubCommand , OutputFormat , ResourceSubCommand } ;
4+ use crate :: args:: { ConfigSubCommand , DscType , ExtensionSubCommand , ListOutputFormat , OutputFormat , ResourceSubCommand } ;
55use crate :: resolve:: { get_contents, Include } ;
66use crate :: resource_command:: { get_resource, self } ;
77use crate :: tablewriter:: Table ;
@@ -611,7 +611,7 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
611611 }
612612}
613613
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 ) {
615615 let mut write_table = false ;
616616 let mut table = Table :: new ( & [
617617 t ! ( "subcommand.tableHeader_type" ) . to_string ( ) . as_ref ( ) ,
@@ -654,7 +654,13 @@ fn list_extensions(dsc: &mut DscManager, extension_name: Option<&String>, format
654654 exit ( EXIT_JSON_ERROR ) ;
655655 }
656656 } ;
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) ;
658664 include_separator = true ;
659665 // insert newline separating instances if writing to console
660666 if io:: stdout ( ) . is_terminal ( ) { println ! ( ) ; }
@@ -663,11 +669,12 @@ fn list_extensions(dsc: &mut DscManager, extension_name: Option<&String>, format
663669 }
664670
665671 if write_table {
666- table. print ( ) ;
672+ let truncate = format != Some ( & ListOutputFormat :: TableNoTruncate ) ;
673+ table. print ( truncate) ;
667674 }
668675}
669676
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 ) {
671678 let mut write_table = false ;
672679 let mut table = Table :: new ( & [
673680 t ! ( "subcommand.tableHeader_type" ) . to_string ( ) . as_ref ( ) ,
@@ -677,7 +684,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
677684 t ! ( "subcommand.tableHeader_adapter" ) . to_string ( ) . as_ref ( ) ,
678685 t ! ( "subcommand.tableHeader_description" ) . to_string ( ) . as_ref ( ) ,
679686 ] ) ;
680- if format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
687+ if format == Some ( & ListOutputFormat :: TableNoTruncate ) || ( format . is_none ( ) && io:: stdout ( ) . is_terminal ( ) ) {
681688 // write as table if format is not specified and interactive
682689 write_table = true ;
683690 }
@@ -759,7 +766,13 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
759766 exit ( EXIT_JSON_ERROR ) ;
760767 }
761768 } ;
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) ;
763776 include_separator = true ;
764777 // insert newline separating instances if writing to console
765778 if io:: stdout ( ) . is_terminal ( ) { println ! ( ) ; }
@@ -768,6 +781,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_
768781 }
769782
770783 if write_table {
771- table. print ( ) ;
784+ let truncate = format != Some ( & ListOutputFormat :: TableNoTruncate ) ;
785+ table. print ( truncate) ;
772786 }
773787}
0 commit comments