Closed ftesser closed 3 years ago
Hi @bw2, I just tested the new release (ConfigArgParse 1.5.2), using the same code reported above, now there is not the error (thanks!), but the functionality is not as I expected.
The issues are:
False
is not taken into consideration and the config.conf is empty:$ python boolean_optional_action_test.py --generate_config_file config.conf
Wrote config file to config.conf
$ cat config.conf
$ python boolean_optional_action_test.py --generate_config_file config.conf --foo
Wrote config file to config.conf
$ cat config.conf
foo = true
the config file correctly contains some info about foo (true), but this is not readable from the parser, in fact parsing this config file return the default foo = False and not the True value contained in the file:
python boolean_optional_action_test.py --config_file config.conf
Namespace(config_file='config.conf', write_out_config_file_to_this_path=None, foo=False)
Any idea of how to manage that?
Hi, newer versions of Python and argparse support
BooleanOptionalAction
(https://docs.python.org/3/library/argparse.html):I tested that with ConfigArgParse this action works at command line level, also it works the writing of the config file, but then if I try to load an exiting configuration there are some errors.
Below an example code (tested with python 3.9.6 and ConfigArgParse 1.5.1
The error probably is derived from the fact that in the config file contains "foo = False" (boolean value) but the BooleanOptionalAction needs just --foo or --no-foo.
Any idea on how to add the support argparse.BooleanOptionalAction in config files of ConfigArgParse?
By the way, this issue should be linked also to this one https://github.com/bw2/ConfigArgParse/issues/209
Thanks!