ConfigArgParse
ConfigArgParse copied to clipboard
Double dash positional argument separator breaks parsing
I looked around to see if this was addressed somewhere but I'm afraid I don't know what to call this feature in the first place so searching was difficult.
With the code
import configargparse as argparse
p = argparse.ArgumentParser()
p.add_argument('--a')
p.add_argument('z')
print(p.parse_args(config_file_contents='a=x'))
running python a.py one
outputs:
Namespace(a='x', z='one')
but python a.py -- one
fails with:
usage: a.py [-h] [--a A] z
a.py: error: unrecognized arguments: --a x
If used with an nargs='*'
parameter this causes the config file option to be parsed as part of that parameter:
import configargparse as argparse
p = argparse.ArgumentParser()
p.add_argument('--a')
p.add_argument('z', nargs='*')
print(p.parse_args(config_file_contents='a=x'))
$ python a.py -- one
Namespace(a=None, z=['one', '--a', 'x'])