bw2 / ConfigArgParse

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.
MIT License
728 stars 121 forks source link

Same argument given multiple times in config file (with action='append') is not appending values as expected #110

Open ismael-elatifi opened 6 years ago

ismael-elatifi commented 6 years ago

Consider : parser.add_argument('--a', action='append')

Following args in command line : --a 1 --a 2 Would correctly give after parsing : Namespace(a=['1','2'])

But the same args in a config file : --a 1 --a 2 Would wrongly give after parsing : Namespace(a='2')

In short, parsing multiple times the same arg (with action='append') from a config file is not appending values as it should (like from command line) but instead keeping only the last value.

bw2 commented 6 years ago

This is likely the same issue as https://github.com/bw2/ConfigArgParse/issues/96

Since you're using the default config file format (rather than .yaml), the current way to specify multiple values is

a=[1,2]

(see REAMDE: https://github.com/bw2/ConfigArgParse#config-file-syntax)

It would be nice to also support the syntax you're using above. If anyone wants to submit a PR for this, I would certainly add it.

kgiloo commented 6 years ago

btw, would it be possible to support the following syntax given at the command line: --a [1,2] which seems to me one of the most intuitive