-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to pass space-separated values with leading dashes #18869
Comments
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aim-for-better, @idear1203. Issue DetailsRequirementTo run Expected JSON: "arguments": [
"--instance",
"trainer"
] Symptom
So the user tries to pass # Line breaks for legibility
az synapse spark job submit --name foo --workspace-name personalizer-trainer --spark-pool-name persbackend --main-definition-file foo --main-class-name org.personalizer.backend.PipelineManager --executors 4 --executor-size Medium
--arguments --instance trainer
argument --arguments: expected at least one argument As discussed in #16044 (comment), it is possible to use an equal sign
However, it doesn't work for multi-value arguments: # Line breaks for legibility
az synapse spark job submit --name foo --workspace-name personalizer-trainer --spark-pool-name persbackend --main-definition-file foo --main-class-name org.personalizer.backend.PipelineManager --executors 4 --executor-size Medium
--arguments=--instance trainer
unrecognized arguments: trainer WorkaroundsThere are several workaround worth considering:
No matter which workaround we choose, it is not an easy fix.
|
Below is why In the # if the option string before the "=" is present, return the action
if '=' in arg_string:
option_string, explicit_arg = arg_string.split('=', 1)
if option_string in self._option_string_actions:
action = self._option_string_actions[option_string]
return action, option_string, explicit_arg Then # if there is an explicit argument, try to match the
# optional's string arguments to only this
if explicit_arg is not None:
arg_count = match_argument(action, 'A') If so, store the value to the argument represented by # if the action expect exactly one argument, we've
# successfully matched the option; exit the loop
elif arg_count == 1:
stop = start_index + 1
args = [explicit_arg]
action_tuples.append((action, args, option_string))
break Notice the line |
Copying my comments from #20663 (comment). For solution 1 (the Now I begin to more and more root for solution 3 (the
This is a common convention in Linux world: |
ConclusionWe decided to use option 3 as the solution for argument passthrough.
Positional argument azure-cli/src/azure-cli/azure/cli/command_modules/storage/_params.py Lines 1292 to 1294 in 215a8b9
This is a common convention in Linux world:
We also got feedback that this is an elegant solution (#20663 (comment)). |
Requirement
To run
az synapse spark job submit
, the user wants to pass--instance
,trainer
as values to--arguments
.Expected JSON:
Symptom
--arguments
is defined asazure-cli/src/azure-cli/azure/cli/command_modules/synapse/_params.py
Line 383 in 39c9174
So the user tries to pass
--instance
,trainer
separated by spaces, and the command fails# Line breaks for legibility az synapse spark job submit --name foo --workspace-name personalizer-trainer --spark-pool-name persbackend --main-definition-file foo --main-class-name org.personalizer.backend.PipelineManager --executors 4 --executor-size Medium --arguments --instance trainer argument --arguments: expected at least one argument
As discussed in #16044 (comment), it is possible to use an equal sign
=
to concatenate the argument name and value for single-value argument:However, it doesn't work for multi-value arguments:
# Line breaks for legibility az synapse spark job submit --name foo --workspace-name personalizer-trainer --spark-pool-name persbackend --main-definition-file foo --main-class-name org.personalizer.backend.PipelineManager --executors 4 --executor-size Medium --arguments=--instance trainer unrecognized arguments: trainer
Workarounds
There are several workaround worth considering:
Instead of using a
nargs='+'
,--arguments
can take single value and split it withshlex.split
Use
nargs=argparse.REMAINDER
to make--arguments
take all remaining arguments.azdev
uses this approach for--pytest-args
and perhaps this is the best way to go.However, this usage has been removed from
argparse
document since Python 3.9 (https://bugs.python.org/issue17050):Replace
--arguments
with the--
convention ofargparse
to mark all remaining arguments as positional arguments (https://docs.python.org/3/library/argparse.html#arguments-containing)Add some special handling in
--arguments
so that dashes can be escaped, like__instance
, or^--instance
. But using characters like`
,\
may cause other trouble with shell's interpretation.No matter which workaround we choose, it is not an easy fix.
The text was updated successfully, but these errors were encountered: