Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable table to screen width wrapping for wide tables #1748

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/snowflake/cli/_app/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions src/snowflake/cli/api/cli_global_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/snowflake/cli/api/commands/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DiagAllowlistPathOption,
DiagLogPathOption,
EnableDiagOption,
FullWidthTableOption,
HostOption,
MasterTokenOption,
MfaPasscodeOption,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/snowflake/cli/api/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/api/test_global_cli_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down