Skip to content

Commit

Permalink
Merge branch 'main' into melnacouzi-fix-post-install-relative-path
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-melnacouzi authored Jul 22, 2024
2 parents 7b9cb57 + e6f348d commit 0bcf5ba
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
supported by setting `token_file_path` in connection definition.
* Support for Python remote execution via `snow stage execute` and `snow git execute` similar to existing EXECUTE IMMEDIATE support.
* Added support for autocomplete in `--connection` flag.
* Added `snow init` command, which supports initializing projects with external templates.

## Fixes and improvements
* The `snow app run` command now allows upgrading to unversioned mode from a versioned or release mode application installation
Expand Down
19 changes: 13 additions & 6 deletions src/snowflake/cli/api/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,22 @@ def _password_callback(value: str):

NoInteractiveOption = typer.Option(False, "--no-interactive", help="Disable prompting.")

VariablesOption = typer.Option(
None,
"--variable",
"-D",
help='Variables for the execution context. For example: `-D "<key>=<value>"`. '

def variables_option(description: str):
return typer.Option(
None,
"--variable",
"-D",
help=description,
show_default=False,
)


ExecuteVariablesOption = variables_option(
'Variables for the execution context. For example: `-D "<key>=<value>"`. '
"For SQL files variables are use to expand the template and any unknown variable will cause an error. "
"For Python files variables are used to update os.environ dictionary. Provided keys are capitalized to adhere to best practices."
"In case of SQL files string values must be quoted in `''` (consider embedding quoting in the file).",
show_default=False,
)


Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/cli/plugins/git/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import typer
from click import ClickException
from snowflake.cli.api.commands.flags import (
ExecuteVariablesOption,
OnErrorOption,
PatternOption,
VariablesOption,
identifier_argument,
like_option,
)
Expand Down Expand Up @@ -276,7 +276,7 @@ def copy(
def execute(
repository_path: str = RepoPathArgument,
on_error: OnErrorType = OnErrorOption,
variables: Optional[List[str]] = VariablesOption,
variables: Optional[List[str]] = ExecuteVariablesOption,
**options,
):
"""
Expand Down
7 changes: 5 additions & 2 deletions src/snowflake/cli/plugins/init/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from click import ClickException
from snowflake.cli.api.commands.flags import (
NoInteractiveOption,
VariablesOption,
parse_key_value_variables,
variables_option,
)
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
Expand Down Expand Up @@ -70,6 +70,9 @@ def _path_argument_callback(path: str) -> str:
default=DEFAULT_SOURCE,
help=f"local path to template directory or URL to git repository with templates.",
)
VariablesOption = variables_option(
"String in `key=value` format. Provided variables will not be prompted for."
)

TEMPLATE_METADATA_FILE_NAME = "template.yml"

Expand Down Expand Up @@ -182,7 +185,7 @@ def _validate_cli_version(required_version: str) -> None:
)


@app.command(no_args_is_help=True, hidden=True)
@app.command(no_args_is_help=True)
def init(
path: str = PathArgument,
template: Optional[str] = TemplateOption,
Expand Down
8 changes: 3 additions & 5 deletions src/snowflake/cli/plugins/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from snowflake.cli.api.commands.decorators import with_project_definition
from snowflake.cli.api.commands.flags import (
parse_key_value_variables,
variables_option,
)
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
from snowflake.cli.api.output.types import CommandResult, MultipleResults, QueryResult
Expand Down Expand Up @@ -55,11 +56,8 @@ def execute_sql(
"-i",
help="Read the query from standard input. Use it when piping input to this command.",
),
data_override: List[str] = typer.Option(
None,
"--variable",
"-D",
help="String in format of key=value. If provided the SQL content will "
data_override: List[str] = variables_option(
"String in format of key=value. If provided the SQL content will "
"be treated as template and rendered using provided data.",
),
**options,
Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/cli/plugins/stage/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import typer
from snowflake.cli.api.cli_global_context import cli_context
from snowflake.cli.api.commands.flags import (
ExecuteVariablesOption,
OnErrorOption,
PatternOption,
VariablesOption,
like_option,
)
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
Expand Down Expand Up @@ -201,7 +201,7 @@ def execute(
show_default=False,
),
on_error: OnErrorType = OnErrorOption,
variables: Optional[List[str]] = VariablesOption,
variables: Optional[List[str]] = ExecuteVariablesOption,
**options,
):
"""
Expand Down
15 changes: 4 additions & 11 deletions tests/__snapshots__/test_help_messages.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| connection Manages connections to Snowflake. |
| cortex Provides access to Snowflake Cortex. |
| git Manages git repositories in Snowflake. |
| init Creates project directory from template. |
| notebook Manages notebooks in Snowflake. |
| object Manages Snowflake objects like warehouses and stages |
| snowpark Manages procedures and functions. |
Expand Down Expand Up @@ -2032,16 +2033,8 @@
| git repository with templates. |
| [default: |
| https://github.com/snowflakedb/snowflake-c… |
| --variable -D TEXT Variables for the execution context. For |
| example: `-D "<key>=<value>"`. For SQL |
| files variables are use to expand the |
| template and any unknown variable will |
| cause an error. For Python files variables |
| are used to update os.environ dictionary. |
| Provided keys are capitalized to adhere to |
| best practices.In case of SQL files string |
| values must be quoted in `''` (consider |
| embedding quoting in the file). |
| --variable -D TEXT String in `key=value` format. Provided |
| variables will not be prompted for. |
| --no-interactive Disable prompting. |
| --help -h Show this message and exit. |
+------------------------------------------------------------------------------+
Expand Down Expand Up @@ -6756,7 +6749,6 @@
| --variable -D TEXT String in format of key=value. If provided the SQL |
| content will be treated as template and rendered |
| using provided data. |
| [default: None] |
| --project -p TEXT Path where Snowflake project resides. Defaults to |
| current working directory. |
| --env TEXT String in format of key=value. Overrides variables |
Expand Down Expand Up @@ -8074,6 +8066,7 @@
| connection Manages connections to Snowflake. |
| cortex Provides access to Snowflake Cortex. |
| git Manages git repositories in Snowflake. |
| init Creates project directory from template. |
| notebook Manages notebooks in Snowflake. |
| object Manages Snowflake objects like warehouses and stages |
| snowpark Manages procedures and functions. |
Expand Down
1 change: 0 additions & 1 deletion tests/__snapshots__/test_sql.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
| --variable -D TEXT String in format of key=value. If provided the SQL |
| content will be treated as template and rendered |
| using provided data. |
| [default: None] |
| --project -p TEXT Path where Snowflake project resides. Defaults to |
| current working directory. |
| --env TEXT String in format of key=value. Overrides variables |
Expand Down
1 change: 1 addition & 0 deletions tests_e2e/__snapshots__/test_installation.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
| connection Manages connections to Snowflake. |
| cortex Provides access to Snowflake Cortex. |
| git Manages git repositories in Snowflake. |
| init Creates project directory from template. |
| notebook Manages notebooks in Snowflake. |
| object Manages Snowflake objects like warehouses and stages |
| snowpark Manages procedures and functions. |
Expand Down

0 comments on commit 0bcf5ba

Please sign in to comment.