diff --git a/src/snowflake/cli/_app/printing.py b/src/snowflake/cli/_app/printing.py index 1dc22bd951..e8936e7d70 100644 --- a/src/snowflake/cli/_app/printing.py +++ b/src/snowflake/cli/_app/printing.py @@ -146,6 +146,9 @@ def print_unstructured(obj: CommandResult | None): elif isinstance(obj, MessageResult): rich_print(sanitize_for_terminal(obj.message), flush=True) else: + full_width_table = get_cli_context().full_width_table + if full_width_table: + get_console().width = sys.maxsize if isinstance(obj, ObjectResult): _print_single_table(obj) elif isinstance(obj, CollectionResult): diff --git a/src/snowflake/cli/api/cli_global_context.py b/src/snowflake/cli/api/cli_global_context.py index 9aae191ec7..1e9a658c6c 100644 --- a/src/snowflake/cli/api/cli_global_context.py +++ b/src/snowflake/cli/api/cli_global_context.py @@ -42,6 +42,7 @@ class _CliGlobalContextManager: ) output_format: OutputFormat = OutputFormat.TABLE + full_width_table: bool = False silent: bool = False verbose: bool = False experimental: bool = False @@ -163,6 +164,10 @@ def metrics(self): def output_format(self) -> OutputFormat: return self._manager.output_format + @property + def full_width_table(self) -> bool: + return self._manager.full_width_table + @property def verbose(self) -> bool: return self._manager.verbose diff --git a/src/snowflake/cli/api/commands/decorators.py b/src/snowflake/cli/api/commands/decorators.py index f06af68183..021fbe215b 100644 --- a/src/snowflake/cli/api/commands/decorators.py +++ b/src/snowflake/cli/api/commands/decorators.py @@ -29,6 +29,7 @@ DiagAllowlistPathOption, DiagLogPathOption, EnableDiagOption, + FullWidthTableOption, HostOption, MasterTokenOption, MfaPasscodeOption, @@ -335,6 +336,12 @@ def _evaluate_param_type( annotation=OutputFormat, default=OutputFormatOption, ), + inspect.Parameter( + "full_width_table", + inspect.Parameter.KEYWORD_ONLY, + annotation=Optional[bool], + default=FullWidthTableOption, + ), inspect.Parameter( "verbose", inspect.Parameter.KEYWORD_ONLY, diff --git a/src/snowflake/cli/api/commands/flags.py b/src/snowflake/cli/api/commands/flags.py index 698a2b0a21..2c91337942 100644 --- a/src/snowflake/cli/api/commands/flags.py +++ b/src/snowflake/cli/api/commands/flags.py @@ -327,6 +327,15 @@ def _diag_log_path_callback(path: str): rich_help_panel=_CLI_BEHAVIOUR, ) +FullWidthTableOption = typer.Option( + False, + "--full-width-table", + help="Table is printed without consideration for screen size, for use with text output and pagers.", + callback=_context_callback("full_width_table"), + is_flag=True, + rich_help_panel=_CLI_BEHAVIOUR, +) + SilentOption = typer.Option( False, "--silent", diff --git a/tests/api/test_global_cli_context.py b/tests/api/test_global_cli_context.py index 1bc1298c4f..f7d7a9f619 100644 --- a/tests/api/test_global_cli_context.py +++ b/tests/api/test_global_cli_context.py @@ -34,6 +34,7 @@ def test_reset_global_context_mgr(): mgr.experimental = True mgr.silent = True mgr.output_format = OutputFormat.JSON + mgr.full_width_table = False mgr.connection_context.database = "blahblah" mgr.connection_context.password = "****" mgr.override_project_definition = "project definition"