Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
a509b8f6
Commit
a509b8f6
authored
Mar 15, 2025
by
Neelay Shah
Committed by
GitHub
Mar 15, 2025
Browse files
feat: updated to override command line and support non equals and space in … (#182)
parent
a2773f3e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
28 deletions
+49
-28
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
+49
-28
No files found.
deploy/dynamo/sdk/src/dynamo/sdk/cli/serve.py
View file @
a509b8f6
...
...
@@ -63,48 +63,63 @@ def deprecated_option(*param_decls: str, **attrs: t.Any):
return
decorator
def
_parse_service_arg
(
arg
:
str
)
->
tuple
[
str
,
str
,
t
.
Any
]
|
None
:
def
_parse_service_arg
(
arg
_name
:
str
,
arg_value
:
str
)
->
tuple
[
str
,
str
,
t
.
Any
]:
"""Parse a single CLI argument into service name, key, and value."""
if
not
(
arg
.
startswith
(
"--"
)
and
"="
in
arg
):
return
None
# Remove leading dashes
param
=
arg
[
2
:]
key_path
,
value_str
=
param
.
split
(
"="
,
1
)
if
"."
not
in
key_path
:
return
None
service
,
key
=
key_path
.
split
(
"."
,
1
)
service
,
key
=
arg_name
.
split
(
"."
,
1
)
# Parse value based on type
try
:
# Try as JSON for complex types
value
=
json
.
loads
(
value
_str
)
value
=
json
.
loads
(
arg_
value
)
except
json
.
JSONDecodeError
:
# Handle basic types
if
value
_str
.
isdigit
():
value
=
int
(
value
_str
)
elif
value
_str
.
replace
(
"."
,
""
,
1
).
isdigit
()
and
value
_str
.
count
(
"."
)
<=
1
:
value
=
float
(
value
_str
)
elif
value
_str
.
lower
()
in
(
"true"
,
"false"
):
value
=
value
_str
.
lower
()
==
"true"
if
arg_
value
.
isdigit
():
value
=
int
(
arg_
value
)
elif
arg_
value
.
replace
(
"."
,
""
,
1
).
isdigit
()
and
arg_
value
.
count
(
"."
)
<=
1
:
value
=
float
(
arg_
value
)
elif
arg_
value
.
lower
()
in
(
"true"
,
"false"
):
value
=
arg_
value
.
lower
()
==
"true"
else
:
value
=
value
_str
value
=
arg_
value
return
service
,
key
,
value
def
_parse_service_args
(
args
:
list
[
str
])
->
t
.
Dict
[
str
,
t
.
Any
]
|
None
:
def
_parse_service_args
(
args
:
list
[
str
])
->
t
.
Dict
[
str
,
t
.
Any
]:
service_configs
:
t
.
DefaultDict
[
str
,
t
.
Dict
[
str
,
t
.
Any
]]
=
collections
.
defaultdict
(
dict
)
for
arg
in
args
:
parsed
=
_parse_service_arg
(
arg
)
if
parsed
:
index
=
0
while
index
<
len
(
args
):
next_arg
=
args
[
index
]
arg_name
=
""
arg_value
=
""
if
not
(
next_arg
.
startswith
(
"--"
)
or
"."
not
in
next_arg
):
continue
try
:
if
"="
in
next_arg
:
arg_name
,
arg_value
=
next_arg
.
split
(
"="
,
1
)
index
+=
1
elif
args
[
index
+
1
]
==
"="
:
arg_name
=
next_arg
arg_value
=
args
[
index
+
2
]
index
+=
3
else
:
arg_name
=
next_arg
arg_value
=
args
[
index
+
1
]
index
+=
2
if
arg_value
.
startswith
(
"-"
):
raise
ValueError
(
"Service arg value can not start with -"
)
arg_name
=
arg_name
[
2
:]
parsed
=
_parse_service_arg
(
arg_name
,
arg_value
)
service
,
key
,
value
=
parsed
service_configs
[
service
][
key
]
=
value
except
Exception
:
raise
ValueError
(
f
"Error parsing service arg:
{
args
[
index
]
}
"
)
return
service_configs
...
...
@@ -331,15 +346,13 @@ def build_serve_command() -> click.Group:
from
dynamo.sdk.lib.service
import
LinkedServices
# Process service-specific options
service_configs
:
t
.
Optional
[
t
.
Dict
[
str
,
t
.
Any
]]
=
_parse_service_args
(
ctx
.
args
)
service_configs
:
dict
[
str
,
dict
[
str
,
t
.
Any
]]
=
{}
# Load
and merge config
file if provided
# Load file if provided
if
file
:
with
open
(
file
)
as
f
:
yaml_configs
=
yaml
.
safe_load
(
f
)
# Initialize service_configs as empty dict if it's None
service_configs
=
dict
(
service_configs
or
{})
# Convert nested YAML structure to flat dict with dot notation
for
service
,
configs
in
yaml_configs
.
items
():
for
key
,
value
in
configs
.
items
():
...
...
@@ -347,7 +360,15 @@ def build_serve_command() -> click.Group:
service_configs
[
service
]
=
{}
service_configs
[
service
][
key
]
=
value
# print("service_configs", service_configs)
# Process Overrides
# Process service-specific options
cmdline_overrides
:
t
.
Dict
[
str
,
t
.
Any
]
=
_parse_service_args
(
ctx
.
args
)
for
service
,
configs
in
cmdline_overrides
.
items
():
for
key
,
value
in
configs
.
items
():
if
service
not
in
service_configs
:
service_configs
[
service
]
=
{}
service_configs
[
service
][
key
]
=
value
# Set environment variable with service configuration
if
service_configs
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment