ConfigArgParse icon indicating copy to clipboard operation
ConfigArgParse copied to clipboard

Error loading configuration file for multiple-argument option with append action

Open clydeclements opened this issue 8 years ago • 1 comments

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.

clydeclements avatar Aug 10 '17 17:08 clydeclements

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.

bw2 avatar Dec 26 '17 19:12 bw2