@@ -615,18 +615,27 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
615615 }
616616}
617617
618+ /// Indicates whether to emit a table based on the output format and whether stdout is a terminal.
619+ fn should_write_table ( format : Option < & ListOutputFormat > ) -> bool {
620+ if matches ! ( format, Some ( ListOutputFormat :: TableNoTruncate ) ) {
621+ // write as table if user specified the table format
622+ true
623+ } else {
624+ // write as table if format is not specified and interactive
625+ format. is_none ( ) && io:: stdout ( ) . is_terminal ( )
626+ }
627+ }
628+
618629fn list_extensions ( dsc : & mut DscManager , extension_name : & TypeNameFilter , format : Option < & ListOutputFormat > , progress_format : ProgressFormat ) {
619- let mut write_table = false ;
630+ let write_table = should_write_table ( format) ;
631+
620632 let mut table = Table :: new ( & [
621633 t ! ( "subcommand.tableHeader_type" ) . to_string ( ) . as_ref ( ) ,
622634 t ! ( "subcommand.tableHeader_version" ) . to_string ( ) . as_ref ( ) ,
623635 t ! ( "subcommand.tableHeader_capabilities" ) . to_string ( ) . as_ref ( ) ,
624636 t ! ( "subcommand.tableHeader_description" ) . to_string ( ) . as_ref ( ) ,
625637 ] ) ;
626- if format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
627- // write as table if format is not specified and interactive
628- write_table = true ;
629- }
638+
630639 let mut include_separator = false ;
631640
632641 for manifest_resource in dsc. list_available ( & DiscoveryKind :: Extension , extension_name, None , progress_format) {
@@ -682,7 +691,7 @@ fn list_extensions(dsc: &mut DscManager, extension_name: &TypeNameFilter, format
682691}
683692
684693fn list_functions ( functions : & FunctionDispatcher , function_name : Option < & String > , output_format : Option < & ListOutputFormat > ) {
685- let mut write_table = false ;
694+ let write_table = should_write_table ( output_format ) ;
686695 let mut table = Table :: new ( & [
687696 t ! ( "subcommand.tableHeader_functionCategory" ) . to_string ( ) . as_ref ( ) ,
688697 t ! ( "subcommand.tableHeader_functionName" ) . to_string ( ) . as_ref ( ) ,
@@ -691,10 +700,7 @@ fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>
691700 t ! ( "subcommand.tableHeader_argTypes" ) . to_string ( ) . as_ref ( ) ,
692701 t ! ( "subcommand.tableHeader_description" ) . to_string ( ) . as_ref ( ) ,
693702 ] ) ;
694- if output_format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
695- // write as table if format is not specified and interactive
696- write_table = true ;
697- }
703+
698704 let mut include_separator = false ;
699705 let returned_types= [
700706 ( FunctionArgKind :: Array , "a" ) ,
0 commit comments