diff --git a/module/core/format_tools/src/format/output_format/table.rs b/module/core/format_tools/src/format/output_format/table.rs index e96af36f20..73e737218d 100644 --- a/module/core/format_tools/src/format/output_format/table.rs +++ b/module/core/format_tools/src/format/output_format/table.rs @@ -247,7 +247,7 @@ impl TableOutputFormat for Table write!( c.buf, "{}", cell_prefix )?; - println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width} | slice.len() : {}", slice.len() ); + // println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width} | slice.len() : {}", slice.len() ); let lspaces = if cell_width > width { 0 diff --git a/module/move/assistant/src/actions/openai_assistants_list.rs b/module/move/assistant/src/actions/openai_assistants_list.rs index 9859761c3b..a6a689c038 100644 --- a/module/move/assistant/src/actions/openai_assistants_list.rs +++ b/module/move/assistant/src/actions/openai_assistants_list.rs @@ -18,13 +18,14 @@ mod private use client::Client; use debug::AssistantObjectWrap; use actions::openai::Result; + use commands::TableConfig; /// Report for `openai assistants list`. #[ derive( Debug ) ] pub struct ListReport { - /// Show records as separate tables. - pub show_records_as_tables : bool, + /// Configure table formatting. + pub table_config : TableConfig, /// OpenAI assistants. pub assistants: Vec< AssistantObjectWrap > @@ -38,7 +39,7 @@ mod private f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - if self.show_records_as_tables + if self.table_config.as_records { writeln!(f, "{}", AsTable::new( &self.assistants ).table_to_string_with_format( &output_format::Records::default() ) ) } @@ -53,12 +54,12 @@ mod private pub async fn action ( client : &Client, - show_records_as_tables : bool, + table_config : TableConfig, ) -> Result < ListReport > { let response = client.list_assistant( None, None, None, None ).await?; let assistants = response.data.into_iter().map( AssistantObjectWrap ).collect(); - Ok( ListReport { show_records_as_tables, assistants } ) + Ok( ListReport { table_config, assistants } ) } } diff --git a/module/move/assistant/src/actions/openai_files_list.rs b/module/move/assistant/src/actions/openai_files_list.rs index 8a3f371a92..8c17567312 100644 --- a/module/move/assistant/src/actions/openai_files_list.rs +++ b/module/move/assistant/src/actions/openai_files_list.rs @@ -18,13 +18,14 @@ mod private use client::Client; use debug::FileDataWrap; use actions::openai::Result; + use commands::TableConfig; /// Report for `openai files list`. #[ derive( Debug ) ] pub struct ListReport { - /// Show records as separate tables. - pub show_records_as_tables : bool, + /// Configure table formatting. + pub table_config : TableConfig, /// Files in OpenAI. pub files : Vec< FileDataWrap > @@ -38,7 +39,7 @@ mod private f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - if self.show_records_as_tables + if self.table_config.as_records { writeln!(f, "{}", AsTable::new( &self.files ).table_to_string_with_format( &output_format::Records::default() ) ) } @@ -53,12 +54,12 @@ mod private pub async fn action ( client : &Client, - show_records_as_tables : bool, + table_config : TableConfig, ) -> Result < ListReport > { let response = client.file_list().await?; let files = response.data.into_iter().map( FileDataWrap ).collect(); - Ok( ListReport { show_records_as_tables, files } ) + Ok( ListReport { table_config, files } ) } } diff --git a/module/move/assistant/src/actions/openai_runs_list.rs b/module/move/assistant/src/actions/openai_runs_list.rs index 631b6ed4cb..4229d3ff62 100644 --- a/module/move/assistant/src/actions/openai_runs_list.rs +++ b/module/move/assistant/src/actions/openai_runs_list.rs @@ -18,16 +18,17 @@ mod private use client::Client; use debug::RunObjectWrap; use actions::openai::Result; + use commands::TableConfig; /// Report for `openai runs list`. #[ derive( Debug ) ] pub struct ListReport { - /// Show records as separate tables. - pub show_records_as_tables : bool, + /// Configure table formatting. + pub table_config : TableConfig, /// Current OpenAI runs. - pub runs : Vec< RunObjectWrap > + pub runs : Vec< RunObjectWrap >, } impl fmt::Display for ListReport @@ -38,7 +39,7 @@ mod private f : &mut fmt::Formatter< '_ > ) -> fmt::Result { - if self.show_records_as_tables + if self.table_config.as_records { writeln!(f, "{}", AsTable::new( &self.runs ).table_to_string_with_format( &output_format::Records::default() ) ) } @@ -54,12 +55,12 @@ mod private ( client : &Client, thread_id : String, - show_records_as_tables : bool, + table_config : TableConfig, ) -> Result < ListReport > { let response = client.list_run( thread_id, None, None, None, None ).await?; let runs = response.data.into_iter().map( RunObjectWrap ).collect(); - Ok( ListReport { show_records_as_tables, runs } ) + Ok( ListReport { table_config, runs } ) } } diff --git a/module/move/assistant/src/bin/main.rs b/module/move/assistant/src/bin/main.rs index adeeaf150f..419030d03b 100644 --- a/module/move/assistant/src/bin/main.rs +++ b/module/move/assistant/src/bin/main.rs @@ -26,7 +26,7 @@ async fn main() -> Result< (), Box< dyn Error > > let secret = Secret::load()?; - let client = client::client( &secret )?; + let client = client( &secret )?; let cli = Cli::parse(); diff --git a/module/move/assistant/src/commands.rs b/module/move/assistant/src/commands.rs index 7a8f56c76c..bfd489cb47 100644 --- a/module/move/assistant/src/commands.rs +++ b/module/move/assistant/src/commands.rs @@ -29,6 +29,21 @@ mod private OpenAi( openai::Command ), } + const DEFAULT_MAX_TABLE_WIDTH: usize = 130; + + /// Common collection of arguments for formatting tabular data. + #[ derive( Debug, Parser ) ] + pub struct TableConfig + { + /// Limit table widht. + #[ arg( long, default_value_t = DEFAULT_MAX_TABLE_WIDTH ) ] + pub max_table_width : usize, + + /// Show records as separate tables. + #[ arg( long, default_value_t = false ) ] + pub as_records : bool, + } + } crate::mod_interface! @@ -45,5 +60,6 @@ crate::mod_interface! { Cli, CliCommand, + TableConfig, }; } diff --git a/module/move/assistant/src/commands/openai_assistants.rs b/module/move/assistant/src/commands/openai_assistants.rs index 66e2d057e8..0d941c94ba 100644 --- a/module/move/assistant/src/commands/openai_assistants.rs +++ b/module/move/assistant/src/commands/openai_assistants.rs @@ -9,7 +9,7 @@ mod private use crate::*; use client::Client; - use commands::openai_assistants_list; + use commands::{ openai_assistants_list, TableConfig }; /// OpenAI assistants. #[ derive ( Debug, Subcommand ) ] @@ -18,9 +18,9 @@ mod private /// List OpenAI assistants. List { - /// Show records as separate tables. - #[ arg( long, default_value_t = false ) ] - show_records_as_tables : bool + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, }, } @@ -33,9 +33,9 @@ mod private { match command { - Command::List{ show_records_as_tables } => + Command::List{ table_config } => { - openai_assistants_list::command( client, show_records_as_tables ).await; + openai_assistants_list::command( client, table_config ).await; } } } diff --git a/module/move/assistant/src/commands/openai_assistants_list.rs b/module/move/assistant/src/commands/openai_assistants_list.rs index 95e1ffb62c..6ce7a80ac4 100644 --- a/module/move/assistant/src/commands/openai_assistants_list.rs +++ b/module/move/assistant/src/commands/openai_assistants_list.rs @@ -8,15 +8,16 @@ mod private use crate::*; use client::Client; use actions; + use commands::TableConfig; /// List OpenAI assistants command. pub async fn command ( client : &Client, - show_records_as_tables : bool, + table_config : TableConfig, ) { - let result = actions::openai_assistants_list::action( client, show_records_as_tables ).await; + let result = actions::openai_assistants_list::action( client, table_config ).await; match result { diff --git a/module/move/assistant/src/commands/openai_files.rs b/module/move/assistant/src/commands/openai_files.rs index 33e18fea0a..ea72a42ad1 100644 --- a/module/move/assistant/src/commands/openai_files.rs +++ b/module/move/assistant/src/commands/openai_files.rs @@ -9,7 +9,7 @@ mod private use crate::*; use client::Client; - use commands::openai_files_list; + use commands::{ openai_files_list, TableConfig }; /// OpenAI files. #[ derive ( Debug, Subcommand ) ] @@ -18,9 +18,9 @@ mod private /// List OpenAI files. List { - /// Show records as separate tables. - #[ arg( long, default_value_t = false ) ] - show_records_as_tables : bool + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, }, } @@ -33,9 +33,9 @@ mod private { match command { - Command::List{ show_records_as_tables } => + Command::List{ table_config } => { - openai_files_list::command( client, show_records_as_tables ).await; + openai_files_list::command( client, table_config ).await; } } } diff --git a/module/move/assistant/src/commands/openai_files_list.rs b/module/move/assistant/src/commands/openai_files_list.rs index 04bc83c0c4..6225b9faf2 100644 --- a/module/move/assistant/src/commands/openai_files_list.rs +++ b/module/move/assistant/src/commands/openai_files_list.rs @@ -8,15 +8,16 @@ mod private use crate::*; use client::Client; use actions; + use commands::TableConfig; /// List files in your OpenAI API. pub async fn command ( client : &Client, - show_records_as_tables : bool, + table_config : TableConfig, ) { - let result = actions::openai_files_list::action( client, show_records_as_tables ).await; + let result = actions::openai_files_list::action( client, table_config ).await; match result { diff --git a/module/move/assistant/src/commands/openai_runs.rs b/module/move/assistant/src/commands/openai_runs.rs index e5e183b33e..2cf7812000 100644 --- a/module/move/assistant/src/commands/openai_runs.rs +++ b/module/move/assistant/src/commands/openai_runs.rs @@ -9,7 +9,7 @@ mod private use crate::*; use client::Client; - use commands::openai_runs_list; + use commands::{ openai_runs_list, TableConfig }; /// OpenAI runs. #[ derive ( Debug, Subcommand ) ] @@ -21,10 +21,10 @@ mod private /// Thread ID. thread_id : String, - /// Show records as separate tables. - #[ arg( long, default_value_t = false ) ] - show_records_as_tables : bool - }, + /// Configure table formatting. + #[ clap( flatten ) ] + table_config : TableConfig, + } } /// Execute OpenAI commands related to runs. @@ -36,9 +36,9 @@ mod private { match command { - Command::List { thread_id, show_records_as_tables } => + Command::List { thread_id, table_config } => { - openai_runs_list::command( client, thread_id, show_records_as_tables ).await; + openai_runs_list::command( client, thread_id, table_config ).await; } } } diff --git a/module/move/assistant/src/commands/openai_runs_list.rs b/module/move/assistant/src/commands/openai_runs_list.rs index 928e0b473a..6d08d64ed3 100644 --- a/module/move/assistant/src/commands/openai_runs_list.rs +++ b/module/move/assistant/src/commands/openai_runs_list.rs @@ -8,16 +8,17 @@ mod private use crate::*; use client::Client; use actions; + use commands::TableConfig; /// List runs in the thread in OpenAI API. pub async fn command ( client : &Client, thread_id : String, - show_records_as_tables : bool, + table_config : TableConfig, ) { - let result = actions::openai_runs_list::action( client, thread_id, show_records_as_tables ).await; + let result = actions::openai_runs_list::action( client, thread_id, table_config ).await; match result {