This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jurko.Gospodnetić
Recipients Jurko.Gospodnetić
Date 2014-08-18.09:46:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1408355162.18.0.7039636355.issue22223@psf.upfronthosting.co.za>
In-reply-to
Content
If you have an optional nargs=argparse.REMAINDER argument defined
then, if specified, its value should contain all the remaining command-line content. However, it seems that value does not include later '--' arguments.

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
'PROG: error: unrecognized arguments: -- ZZ':

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
positional nargs=argparse.REMAINDER arguments:

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
start with something like "--blah" that looks like an optional
argument.


Hope this helps.

Best regards,
  Jurko Gospodnetić
History
Date User Action Args
2014-08-18 09:46:02Jurko.Gospodnetićsetrecipients: + Jurko.Gospodnetić
2014-08-18 09:46:02Jurko.Gospodnetićsetmessageid: <1408355162.18.0.7039636355.issue22223@psf.upfronthosting.co.za>
2014-08-18 09:46:02Jurko.Gospodnetićlinkissue22223 messages
2014-08-18 09:46:01Jurko.Gospodnetićcreate