ConfigArgParse
ConfigArgParse copied to clipboard
Error loading configuration file for multiple-argument option with append action
There is an issue when loading a configuration file for an option that allows multiple arguments (nargs > 1) and has the action set to append. For example, consider this script called test.py:
import configargparse
p = configargparse.ArgParser(
config_file_parser_class=configargparse.YAMLConfigFileParser,
args_for_writing_out_config_file=['-w', '--write-out-config-file']
)
p.add('-c', '--config', is_config_file=True, help='config file path')
p.add('-i', '--indexes', type=int, metavar=('x', 'y'), nargs=2,
action='append')
options = p.parse_args()
print(options)
print("----------")
print(p.format_help())
print("----------")
print(p.format_values())
and this sample configuration file test.yaml:
indexes:
- - 2
- 4
- - 1
- 9
Running the script as follows:
python test.py -c test.yaml
gives the following error message:
usage: test.py [-h] [-w CONFIG_OUTPUT_PATH] [-c CONFIG] [-i x y]
test.py: error: argument -i/--indexes: expected 2 arguments
I had expected configargparse to correctly load the configuration file.
The current way to provide a list of values (REAMDE section: https://github.com/bw2/ConfigArgParse#config-file-syntax) is a hack that I put in a few iterations prior to adding YAML support.
If somebody can take on adding full list support, it would be much appreciated.