-
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
Specifying --output
at top level corrupts subcommand configuration
#7877
Comments
I believe you have to put all commands (main and sub commands) up to front before any arguments following. Not doing that, the error reporting will not be decent |
Hi @yugangw-msft! Thanks for the quick response. I understand this isn't the intended order, but I think we should give good error messages if the user happens to provide options/subcommands in an unintended order. This might not be a bug in the sense that providing |
add to S164. |
This is actually a very good catch, but given the technical complication and frequency of this usage, I prefer not to fix it. Workaround Use the config file to configure global output format. Analysis When
Example:
⚠Changing azure-cli/src/azure-cli-core/azure/cli/core/parser.py Lines 84 to 91 in 2caccaa
This is some limitation imposed by argparse and can be verified with a sample: import argparse
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--output', default='json')
subparsers = parser.add_subparsers()
parser_a = subparsers.add_parser('a', parents=[parser])
parser_a.add_argument('--bar')
print(parser.parse_args(['--output', 'yaml', 'a', '--bar', 'Z']))
print(parser.parse_args(['a', '--bar', 'Z', '--output', 'yaml'])) Output: Namespace(bar='Z', output='json') # Notice yaml doesn't make it way to the parsed namespace
Namespace(bar='Z', output='yaml') Also, Another complication is that if |
Describe the bug
Using the
--output
option (and possibly other options) causes subcommands to print incorrect help information, and execute incorrect code paths.To Reproduce
Use the
--output
common option before the subcommands. Here are a few examples and the confusing output they generate:Expected behavior
Compare the above commands to the results when
--output
is in the "correct" place:Even if specifying
--output
at the start of the args list isn't supported, I would expect to see an error or some indication that the argument is unrecognised or invalid at the position given. I do not expect to see an exception (as in the third example) or a failure of the CLI to correctly list subcommands (as in examples one and two).Environment summary
MSI on Windows 10. Full details below:
`az --version` output
The text was updated successfully, but these errors were encountered: