39
39
QueryJsonValueResult ,
40
40
QueryResult ,
41
41
)
42
+ from snowflake .cli .api .utils .path_utils import is_stage_path
42
43
43
44
app = SnowTyperFactory (
44
45
name = "dcm" ,
56
57
help = "Configuration of the DCM Project to use. If not specified default configuration is used." ,
57
58
show_default = False ,
58
59
)
59
- from_option = OverrideableOption (
60
+ from_option = typer . Option (
60
61
None ,
61
62
"--from" ,
63
+ help = "Source location: stage path (starting with '@') or local directory path. Omit to use current directory." ,
62
64
show_default = False ,
63
65
)
64
66
106
108
@app .command (requires_connection = True )
107
109
def deploy (
108
110
identifier : FQN = dcm_identifier ,
109
- from_stage : Optional [str ] = from_option (
110
- help = "Deploy DCM Project deployment from a given stage."
111
- ),
111
+ from_location : Optional [str ] = from_option ,
112
112
variables : Optional [List [str ]] = variables_flag ,
113
113
configuration : Optional [str ] = configuration_flag ,
114
114
alias : Optional [str ] = alias_option ,
@@ -118,14 +118,14 @@ def deploy(
118
118
Applies changes defined in DCM Project to Snowflake.
119
119
"""
120
120
manager = DCMProjectManager ()
121
- if not from_stage :
122
- from_stage = manager . sync_local_files ( project_identifier = identifier )
121
+ effective_stage = _get_effective_stage ( identifier , from_location )
122
+
123
123
with cli_console .spinner () as spinner :
124
124
spinner .add_task (description = f"Deploying dcm project { identifier } " , total = None )
125
125
result = manager .execute (
126
126
project_identifier = identifier ,
127
127
configuration = configuration ,
128
- from_stage = from_stage ,
128
+ from_stage = effective_stage ,
129
129
variables = variables ,
130
130
alias = alias ,
131
131
output_path = None ,
@@ -136,9 +136,7 @@ def deploy(
136
136
@app .command (requires_connection = True )
137
137
def plan (
138
138
identifier : FQN = dcm_identifier ,
139
- from_stage : Optional [str ] = from_option (
140
- help = "Plan DCM Project deployment from a given stage."
141
- ),
139
+ from_location : Optional [str ] = from_option ,
142
140
variables : Optional [List [str ]] = variables_flag ,
143
141
configuration : Optional [str ] = configuration_flag ,
144
142
output_path : Optional [str ] = output_path_option (
@@ -150,15 +148,14 @@ def plan(
150
148
Plans a DCM Project deployment (validates without executing).
151
149
"""
152
150
manager = DCMProjectManager ()
153
- if not from_stage :
154
- from_stage = manager .sync_local_files (project_identifier = identifier )
151
+ effective_stage = _get_effective_stage (identifier , from_location )
155
152
156
153
with cli_console .spinner () as spinner :
157
154
spinner .add_task (description = f"Planning dcm project { identifier } " , total = None )
158
155
result = manager .execute (
159
156
project_identifier = identifier ,
160
157
configuration = configuration ,
161
- from_stage = from_stage ,
158
+ from_stage = effective_stage ,
162
159
dry_run = True ,
163
160
variables = variables ,
164
161
output_path = output_path ,
@@ -236,3 +233,16 @@ def drop_deployment(
236
233
return MessageResult (
237
234
f"Deployment '{ deployment_name } ' dropped from DCM Project '{ identifier } '."
238
235
)
236
+
237
+
238
+ def _get_effective_stage (identifier : FQN , from_location : Optional [str ]):
239
+ manager = DCMProjectManager ()
240
+ if not from_location :
241
+ from_stage = manager .sync_local_files (project_identifier = identifier )
242
+ elif is_stage_path (from_location ):
243
+ from_stage = from_location
244
+ else :
245
+ from_stage = manager .sync_local_files (
246
+ project_identifier = identifier , source_directory = from_location
247
+ )
248
+ return from_stage
0 commit comments