Skip to content

Commit 998a747

Browse files
feat: [SNOW-2017083] make version flag optional in snow project execu… (#2163)
feat: [SNOW-2017083] make version flag optional in snow project execute/dry-run
1 parent f3894e3 commit 998a747

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747

4848
project_identifier = identifier_argument(sf_object="project", example="MY_PROJECT")
4949
version_flag = typer.Option(
50-
..., "--version", help="Version of the project to use.", show_default=False
50+
None,
51+
"--version",
52+
help="Version of the project to use. If not specified default version is used",
53+
show_default=False,
5154
)
5255
variables_flag = variables_option(
5356
'Variables for the execution context; for example: `-D "<key>=<value>"`.'
@@ -69,7 +72,7 @@
6972
@app.command(requires_connection=True)
7073
def execute(
7174
identifier: FQN = project_identifier,
72-
version: str = version_flag,
75+
version: Optional[str] = version_flag,
7376
variables: Optional[List[str]] = variables_flag,
7477
**options,
7578
):
@@ -85,7 +88,7 @@ def execute(
8588
@app.command(requires_connection=True)
8689
def dry_run(
8790
identifier: FQN = project_identifier,
88-
version: str = version_flag,
91+
version: Optional[str] = version_flag,
8992
variables: Optional[List[str]] = variables_flag,
9093
**options,
9194
):

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from snowflake.cli.api.identifiers import FQN
2020
from snowflake.cli.api.sql_execution import SqlExecutionMixin
2121
from snowflake.cli.api.stage_path import StagePath
22+
from snowflake.connector.cursor import SnowflakeCursor
2223

2324

2425
class ProjectManager(SqlExecutionMixin):
@@ -43,7 +44,7 @@ def execute(
4344
def create(
4445
self,
4546
project_name: FQN,
46-
) -> str:
47+
) -> SnowflakeCursor:
4748
queries = dedent(f"CREATE PROJECT IF NOT EXISTS {project_name.sql_identifier}")
4849
return self.execute_query(query=queries)
4950

tests/__snapshots__/test_help_messages.ambr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6208,11 +6208,11 @@
62086208
| [required] |
62096209
+------------------------------------------------------------------------------+
62106210
+- Options --------------------------------------------------------------------+
6211-
| * --version TEXT Version of the project to use. |
6212-
| [required] |
6213-
| --variable -D TEXT Variables for the execution context; for |
6214-
| example: -D "<key>=<value>". |
6215-
| --help -h Show this message and exit. |
6211+
| --version TEXT Version of the project to use. If not specified |
6212+
| default version is used |
6213+
| --variable -D TEXT Variables for the execution context; for example: |
6214+
| -D "<key>=<value>". |
6215+
| --help -h Show this message and exit. |
62166216
+------------------------------------------------------------------------------+
62176217
+- Connection configuration ---------------------------------------------------+
62186218
| --connection,--environment -c TEXT Name of the connection, as |
@@ -6306,11 +6306,11 @@
63066306
| [required] |
63076307
+------------------------------------------------------------------------------+
63086308
+- Options --------------------------------------------------------------------+
6309-
| * --version TEXT Version of the project to use. |
6310-
| [required] |
6311-
| --variable -D TEXT Variables for the execution context; for |
6312-
| example: -D "<key>=<value>". |
6313-
| --help -h Show this message and exit. |
6309+
| --version TEXT Version of the project to use. If not specified |
6310+
| default version is used |
6311+
| --variable -D TEXT Variables for the execution context; for example: |
6312+
| -D "<key>=<value>". |
6313+
| --help -h Show this message and exit. |
63146314
+------------------------------------------------------------------------------+
63156315
+- Connection configuration ---------------------------------------------------+
63166316
| --connection,--environment -c TEXT Name of the connection, as |

tests/dcm_project/test_dcm_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ def test_add_version(mock_pm, runner, project_directory):
8989

9090
@mock.patch(ProjectManager)
9191
def test_execute_project(mock_pm, runner, project_directory):
92-
result = runner.invoke(["project", "execute", "fooBar", "--version", "v1"])
92+
result = runner.invoke(["project", "execute", "fooBar"])
9393
assert result.exit_code == 0, result.output
9494

9595
mock_pm().execute.assert_called_once_with(
9696
project_name=FQN.from_string("fooBar"),
97-
version="v1",
97+
version=None,
9898
variables=None,
9999
)
100100

tests/dcm_project/test_dcm_project_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ def test_execute_project(mock_execute_query, runner, project_directory):
4242
)
4343

4444

45+
@mock.patch(execute_queries)
46+
def test_execute_project_with_default_version(
47+
mock_execute_query, runner, project_directory
48+
):
49+
mgr = ProjectManager()
50+
51+
mgr.execute(project_name=TEST_PROJECT, version=None)
52+
53+
mock_execute_query.assert_called_once_with(
54+
query="EXECUTE PROJECT IDENTIFIER('my_project')"
55+
)
56+
57+
4558
@mock.patch(execute_queries)
4659
def test_validate_project(mock_execute_query, runner, project_directory):
4760
mgr = ProjectManager()

tests_integration/test_dcm_project.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def test_project_deploy(
3838
"project",
3939
"execute",
4040
"my_project",
41-
"--version",
42-
"last",
4341
"-D",
4442
f"table_name='{test_database}.PUBLIC.MyTable'",
4543
]

0 commit comments

Comments
 (0)