Issue 84 in argparse: positional arguments before options cause all options to be in REMAINDER

2 views
Skip to first unread message

argp...@googlecode.com

unread,
Feb 27, 2012, 4:59:14 PM2/27/12
to argpar...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 84 by jdaw...@gmail.com: positional arguments before options
cause all options to be in REMAINDER
http://code.google.com/p/argparse/issues/detail?id=84

What steps will reproduce the problem?

import argparse
argp = argparse.ArgumentParser(""" some description """")
argp.add_argument('-j', action='store', type=str, dest='jql', default=None)
argp.add_argument('-v', action='version', version='1.0.0')
argp.add_argument('-p', action='store', dest='project', default=None)
argp.add_argument('argv', nargs=argparse.REMAINDER)
args = argp.parse_args()
print(args)

What is the expected output? What do you see instead?

python3 test.py server userid pass -j 'key=blah'
Namespace(argv=['server', 'userid', 'pass', '-j', 'key=blah'], jql=None,
project=None)

but if I reorganize the command line to have the positional args last, I
get what I expected in the first place:

python3 x.py -j 'key=blah' server userid pass
Namespace(argv=['server', 'userid', 'pass'], jql='key=blah', project=None)

What version of the product are you using? On what operating system?


Please provide any additional information below.

It would appear the positional arguments HAVE to be after any optional ones.
Unix/Linux of course allows this.


Reply all
Reply to author
Forward
0 new messages