-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
argparse not including '--' arguments in previous optional REMAINDER argument #66419
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
Comments
If you have an optional nargs=argparse.REMAINDER argument defined For example, the following works as expected: import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("--args", nargs=argparse.REMAINDER)
args = parser.parse_args("--args cmd --arg1 XX ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "ZZ"] But the following fails with import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("--args", nargs=argparse.REMAINDER)
args = parser.parse_args("--args cmd --arg1 XX -- ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"] Note that the same code works as expected when using a import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("args", nargs=argparse.REMAINDER)
args = parser.parse_args("args cmd --arg1 XX ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "ZZ"]
args = parser.parse_args("args cmd --arg1 XX -- ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"] But that, of course, does not allow us to have the args value Hope this helps. Best regards, |
Might be related to the following issues: http://bugs.python.org/issue9571 |
REMAINDER is currently undocumented (see bpo-17050/gh-61252), but the proposed change looks right. This would allow to use REMAINDER to simulate a subparser with option as the command (currently the subparser machinery does not support this). I believe it is just an omission that this was not supported before. |
…all arguments It no longer stops at the first '--'.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: