Skip to content

Commit be4cd60

Browse files
feat: [SNOW-2236093] add terse and limit options to list aliases (#2524)
1 parent 30dd1c4 commit be4cd60

File tree

10 files changed

+232
-152
lines changed

10 files changed

+232
-152
lines changed

src/snowflake/cli/_plugins/dcm/commands.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
show_default=False,
9191
)
9292

93+
terse_option = typer.Option(
94+
False,
95+
"--terse",
96+
help="Returns only a subset of output columns.",
97+
show_default=False,
98+
)
99+
100+
limit_option = typer.Option(
101+
None,
102+
"--limit",
103+
help="Limits the maximum number of rows returned.",
104+
show_default=False,
105+
)
106+
93107

94108
add_object_command_aliases(
95109
app=app,
@@ -100,6 +114,8 @@
100114
),
101115
scope_option=scope_option(help_example="`list --in database my_db`"),
102116
ommit_commands=["create"],
117+
terse_option=terse_option,
118+
limit_option=limit_option,
103119
)
104120

105121

src/snowflake/cli/_plugins/object/command_aliases.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
ScopeOption,
2323
describe,
2424
drop,
25+
limit_option_,
2526
list_,
2627
scope_option, # noqa: F401
28+
terse_option_,
2729
)
2830
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
2931
from snowflake.cli.api.constants import ObjectType
@@ -37,6 +39,8 @@ def add_object_command_aliases(
3739
like_option: Optional[typer.Option],
3840
scope_option: Optional[typer.Option],
3941
ommit_commands: Optional[List[str]] = None,
42+
terse_option: Optional[typer.Option] = None,
43+
limit_option: Optional[typer.Option] = None,
4044
):
4145
if ommit_commands is None:
4246
ommit_commands = list()
@@ -47,11 +51,18 @@ def add_object_command_aliases(
4751
if not scope_option:
4852

4953
@app.command("list", requires_connection=True)
50-
def list_cmd(like: str = like_option, **options): # type: ignore
54+
def list_cmd(
55+
like: str = like_option, # type: ignore
56+
terse: bool = terse_option if terse_option else terse_option_(), # type: ignore
57+
limit: Optional[int] = limit_option if limit_option else limit_option_(), # type: ignore
58+
**options,
59+
):
5160
return list_(
5261
object_type=object_type.value.cli_name,
5362
like=like,
5463
scope=ScopeOption.default,
64+
terse=terse,
65+
limit=limit,
5566
**options,
5667
)
5768

@@ -61,12 +72,16 @@ def list_cmd(like: str = like_option, **options): # type: ignore
6172
def list_cmd(
6273
like: str = like_option, # type: ignore
6374
scope: Tuple[str, str] = scope_option, # type: ignore
75+
terse: bool = terse_option if terse_option else terse_option_(), # type: ignore
76+
limit: Optional[int] = limit_option if limit_option else limit_option_(), # type: ignore
6477
**options,
6578
):
6679
return list_(
6780
object_type=object_type.value.cli_name,
6881
like=like,
6982
scope=scope,
83+
terse=terse,
84+
limit=limit,
7085
**options,
7186
)
7287

src/snowflake/cli/_plugins/object/commands.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ def scope_option(help_example: str):
9494
)
9595

9696

97+
def terse_option_():
98+
return typer.Option(
99+
None,
100+
"--terse",
101+
help=f"Returns only a subset of available columns.",
102+
hidden=True,
103+
)
104+
105+
106+
def limit_option_():
107+
return typer.Option(
108+
None,
109+
"--limit",
110+
help=f"Limits the maximum number of rows returned.",
111+
hidden=True,
112+
)
113+
114+
97115
ScopeOption = scope_option(
98116
help_example="`list table --in database my_db`. Some object types have specialized scopes (e.g. list service --in compute-pool my_pool)"
99117
)
@@ -110,11 +128,19 @@ def list_(
110128
object_type: str = ObjectArgument,
111129
like: str = LikeOption,
112130
scope: Tuple[str, str] = ScopeOption,
131+
terse: Optional[bool] = terse_option_(),
132+
limit: Optional[int] = limit_option_(),
113133
**options,
114134
):
115135
_scope_validate(object_type, scope)
116136
return QueryResult(
117-
ObjectManager().show(object_type=object_type, like=like, scope=scope)
137+
ObjectManager().show(
138+
object_type=object_type,
139+
like=like,
140+
scope=scope,
141+
terse=terse,
142+
limit=limit,
143+
)
118144
)
119145

120146

src/snowflake/cli/_plugins/object/manager.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,25 @@ def show(
4444
object_type: str,
4545
like: Optional[str] = None,
4646
scope: Union[Tuple[str, str], Tuple[None, None]] = (None, None),
47+
terse: Optional[bool] = False,
48+
limit: Optional[int] = None,
4749
**kwargs,
4850
) -> SnowflakeCursor:
4951
object_name = _get_object_names(object_type).sf_plural_name
50-
query = f"show {object_name}"
52+
query_parts = ["show"]
53+
54+
if terse:
55+
query_parts.append("terse")
56+
57+
query_parts.append(object_name)
58+
query = " ".join(query_parts)
59+
5160
if like:
5261
query += f" like '{like}'"
5362
if scope[0] is not None:
5463
query += f" in {scope[0].replace('-', ' ')} {scope[1]}"
64+
if limit is not None:
65+
query += f" limit {limit}"
5566
return self.execute_query(query, **kwargs)
5667

5768
def drop(self, *, object_type: str, fqn: FQN) -> SnowflakeCursor:

src/snowflake/cli/_plugins/snowpark/commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,14 @@ def list_(
448448
**options,
449449
):
450450
"""Lists all available procedures or functions."""
451-
return object_list(object_type=object_type.value, like=like, scope=scope, **options)
451+
return object_list(
452+
object_type=object_type.value,
453+
like=like,
454+
scope=scope,
455+
terse=None,
456+
limit=None,
457+
**options,
458+
)
452459

453460

454461
@app.command("drop", requires_connection=True)

tests/__snapshots__/test_help_messages.ambr

Lines changed: 12 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,141 +7620,6 @@
76207620
+------------------------------------------------------------------------------+
76217621

76227622

7623-
'''
7624-
# ---
7625-
# name: test_help_messages[dcm.drop-version]
7626-
'''
7627-
7628-
Usage: root dcm drop-version [OPTIONS] IDENTIFIER VERSION_NAME
7629-
7630-
Drops a version from the DCM Project.
7631-
7632-
7633-
+- Arguments ------------------------------------------------------------------+
7634-
| * identifier TEXT Identifier of the DCM Project; for example: |
7635-
| MY_PROJECT |
7636-
| [required] |
7637-
| * version_name TEXT Name or alias of the version to drop. For names |
7638-
| containing '$', use single quotes to prevent |
7639-
| shell expansion (e.g., 'VERSION$1'). |
7640-
| [required] |
7641-
+------------------------------------------------------------------------------+
7642-
+- Options --------------------------------------------------------------------+
7643-
| --if-exists Do nothing if the version does not exist. |
7644-
| --help -h Show this message and exit. |
7645-
+------------------------------------------------------------------------------+
7646-
+- Connection configuration ---------------------------------------------------+
7647-
| --connection,--environment -c TEXT Name of the connection, as |
7648-
| defined in your config.toml |
7649-
| file. Default: default. |
7650-
| --host TEXT Host address for the |
7651-
| connection. Overrides the |
7652-
| value specified for the |
7653-
| connection. |
7654-
| --port INTEGER Port for the connection. |
7655-
| Overrides the value specified |
7656-
| for the connection. |
7657-
| --account,--accountname TEXT Name assigned to your |
7658-
| Snowflake account. Overrides |
7659-
| the value specified for the |
7660-
| connection. |
7661-
| --user,--username TEXT Username to connect to |
7662-
| Snowflake. Overrides the |
7663-
| value specified for the |
7664-
| connection. |
7665-
| --password TEXT Snowflake password. Overrides |
7666-
| the value specified for the |
7667-
| connection. |
7668-
| --authenticator TEXT Snowflake authenticator. |
7669-
| Overrides the value specified |
7670-
| for the connection. |
7671-
| --private-key-file,--privat… TEXT Snowflake private key file |
7672-
| path. Overrides the value |
7673-
| specified for the connection. |
7674-
| --token TEXT OAuth token to use when |
7675-
| connecting to Snowflake. |
7676-
| --token-file-path TEXT Path to file with an OAuth |
7677-
| token to use when connecting |
7678-
| to Snowflake. |
7679-
| --database,--dbname TEXT Database to use. Overrides |
7680-
| the value specified for the |
7681-
| connection. |
7682-
| --schema,--schemaname TEXT Database schema to use. |
7683-
| Overrides the value specified |
7684-
| for the connection. |
7685-
| --role,--rolename TEXT Role to use. Overrides the |
7686-
| value specified for the |
7687-
| connection. |
7688-
| --warehouse TEXT Warehouse to use. Overrides |
7689-
| the value specified for the |
7690-
| connection. |
7691-
| --temporary-connection -x Uses a connection defined |
7692-
| with command line parameters, |
7693-
| instead of one defined in |
7694-
| config |
7695-
| --mfa-passcode TEXT Token to use for multi-factor |
7696-
| authentication (MFA) |
7697-
| --enable-diag Whether to generate a |
7698-
| connection diagnostic report. |
7699-
| --diag-log-path TEXT Path for the generated |
7700-
| report. Defaults to system |
7701-
| temporary directory. |
7702-
| --diag-allowlist-path TEXT Path to a JSON file that |
7703-
| contains allowlist |
7704-
| parameters. |
7705-
| --oauth-client-id TEXT Value of client id provided |
7706-
| by the Identity Provider for |
7707-
| Snowflake integration. |
7708-
| --oauth-client-secret TEXT Value of the client secret |
7709-
| provided by the Identity |
7710-
| Provider for Snowflake |
7711-
| integration. |
7712-
| --oauth-authorization-url TEXT Identity Provider endpoint |
7713-
| supplying the authorization |
7714-
| code to the driver. |
7715-
| --oauth-token-request-url TEXT Identity Provider endpoint |
7716-
| supplying the access tokens |
7717-
| to the driver. |
7718-
| --oauth-redirect-uri TEXT URI to use for authorization |
7719-
| code redirection. |
7720-
| --oauth-scope TEXT Scope requested in the |
7721-
| Identity Provider |
7722-
| authorization request. |
7723-
| --oauth-disable-pkce Disables Proof Key for Code |
7724-
| Exchange (PKCE). Default: |
7725-
| False. |
7726-
| --oauth-enable-refresh-toke… Enables a silent |
7727-
| re-authentication when the |
7728-
| actual access token becomes |
7729-
| outdated. Default: False. |
7730-
| --oauth-enable-single-use-r… Whether to opt-in to |
7731-
| single-use refresh token |
7732-
| semantics. Default: False. |
7733-
| --client-store-temporary-cr… Store the temporary |
7734-
| credential. |
7735-
+------------------------------------------------------------------------------+
7736-
+- Global configuration -------------------------------------------------------+
7737-
| --format [TABLE|JSON|JSON_EXT| Specifies the output |
7738-
| CSV] format. |
7739-
| [default: TABLE] |
7740-
| --verbose -v Displays log entries |
7741-
| for log levels info |
7742-
| and higher. |
7743-
| --debug Displays log entries |
7744-
| for log levels debug |
7745-
| and higher; debug logs |
7746-
| contain additional |
7747-
| information. |
7748-
| --silent Turns off intermediate |
7749-
| output to console. |
7750-
| --enhanced-exit-codes Differentiate exit |
7751-
| error codes based on |
7752-
| failure type. |
7753-
| [env var: |
7754-
| SNOWFLAKE_ENHANCED_EX… |
7755-
+------------------------------------------------------------------------------+
7756-
7757-
77587623
'''
77597624
# ---
77607625
# name: test_help_messages[dcm.drop]
@@ -8025,17 +7890,19 @@
80257890

80267891

80277892
+- Options --------------------------------------------------------------------+
8028-
| --like -l TEXT SQL LIKE pattern for filtering objects by |
8029-
| name. For example, list --like "my%" lists |
8030-
| all DCM Projects that begin with "my". |
8031-
| [default: %%] |
8032-
| --in <TEXT TEXT>... |
7893+
| --like -l TEXT SQL LIKE pattern for filtering objects by |
7894+
| name. For example, list --like "my%" lists |
7895+
| all DCM Projects that begin with "my". |
7896+
| [default: %%] |
7897+
| --in <TEXT TEXT>... |
80337898
| |
8034-
| Specifies the scope of this command using |
8035-
| '--in ', for example list --in database |
8036-
| my_db. |
8037-
| [default: None, None] |
8038-
| --help -h Show this message and exit. |
7899+
| Specifies the scope of this command using |
7900+
| '--in ', for example list --in database |
7901+
| my_db. |
7902+
| [default: None, None] |
7903+
| --terse Returns only a subset of output columns. |
7904+
| --limit INTEGER Limits the maximum number of rows returned. |
7905+
| --help -h Show this message and exit. |
80397906
+------------------------------------------------------------------------------+
80407907
+- Connection configuration ---------------------------------------------------+
80417908
| --connection,--environment -c TEXT Name of the connection, as |

0 commit comments

Comments
 (0)