Skip to content

Commit

Permalink
Add maximum table width to assistants CLI (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan authored Dec 2, 2024
1 parent d762865 commit 039445d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion module/move/assistant/src/bin/list_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use dotenv::dotenv;

use assistant::
{
client,
client::client,
Secret
};

Expand Down
8 changes: 3 additions & 5 deletions module/move/assistant/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ mod private
OpenAi( openai::Command ),
}

// const DEFAULT_MAX_TABLE_WIDTH: usize = 130;
// Commented out as not yet implemented in `format_tools`.
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,
// Commented out as not yet implemented in `format_tools`.
#[ arg( long, default_value_t = DEFAULT_MAX_TABLE_WIDTH ) ]
pub max_table_width : usize,

/// Show tabular data as an ordinary table.
#[ arg( long ) ]
Expand Down
49 changes: 38 additions & 11 deletions module/move/assistant/src/util/display_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,58 +28,85 @@ mod private
{
if table_config.as_table
{
display_table( data, f, &table_config.filter_columns )
display_table( data, f, table_config )
}
else if table_config.as_records
{
display_records( data, f, &table_config.filter_columns )
display_records( data, f, table_config )
}
else if table_config.columns
{
display_columns( data, f, &table_config.filter_columns )
display_columns( data, f, table_config )
}
else
{
display_table( data, f, &table_config.filter_columns )
display_table( data, f, table_config )
}
}

fn display_table<'a>
(
data : &'a impl TableFormatter< 'a >,
f : &mut fmt::Formatter< '_ >,
filter_columns : &'a Vec< String >,
table_config : &'a TableConfig,
) -> fmt::Result
{
display_data( data, f, filter_columns, output_format::Table::default() )
let mut format = output_format::Table::default();
format.max_width = table_config.max_table_width;

display_data
(
data,
f,
format,
&table_config.filter_columns,
)
}

fn display_records<'a>
(
data : &'a impl TableFormatter< 'a >,
f : &mut fmt::Formatter< '_ >,
filter_columns : &'a Vec< String >,
table_config : &'a TableConfig,
) -> fmt::Result
{
display_data( data, f, filter_columns, output_format::Records::default() )
let mut format = output_format::Records::default();
format.max_width = table_config.max_table_width;

display_data
(
data,
f,
format,
&table_config.filter_columns,
)
}

fn display_columns<'a>
(
data : &'a impl TableFormatter< 'a >,
f : &mut fmt::Formatter< '_ >,
filter_columns : &'a Vec< String >,
table_config : &'a TableConfig,
) -> fmt::Result
{
display_data( data, f, filter_columns, output_format::Keys::default() )
let mut format = output_format::Records::default();
format.max_width = table_config.max_table_width;

display_data
(
data,
f,
format,
&table_config.filter_columns,
)
}

fn display_data<'a>
(
data : &'a impl TableFormatter< 'a >,
f : &mut fmt::Formatter< '_ >,
filter_columns : &'a Vec< String >,
format : impl TableOutputFormat,
filter_columns : &'a Vec< String >,
) -> fmt::Result
{
let mut printer = print::Printer::with_format( &format );
Expand Down

0 comments on commit 039445d

Please sign in to comment.