ThomasWaldmann / argparse

python argparse, pypi version (moved from google code)
Other
59 stars 18 forks source link

positional arguments before options cause all options to be in REMAINDER #84

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by jdaw...@gmail.com on 27 Feb 2012 at 9:58

ThomasWaldmann commented 9 years ago

argparse from the builtin standard library of python 2.7.6 behaves exactly the same as you have reported above.

So, please read issue #81 and continue on the correct issue tracker.