ConfigArgParse
ConfigArgParse copied to clipboard
add_help=False prevents reading of config file if option -h is used on the command line
Minimal test script to show the error:
import configargparse
ap = configargparse.ArgParser(add_help=False, default_config_files=['test.conf'])
ap.add_argument('--help', action="help", help="Show help message")
ap.add_argument('-h', '--host', default='localhost', help="hostname")
ap.add_argument('-p', '--port', type=int, default=80, help="port")
args = ap.parse_args()
print(vars(args))
Config file test.conf:
host = myhost
port = 8080
$ python test_configargparse_help.py --help
usage: test_configargparse_help.py [--help] [-h HOST] [-p PORT]
Args that start with '--' (eg. -h) can also be set in a config file [...]
optional arguments:
--help Show help message
-h HOST, --host HOST hostname
-p PORT, --port PORT port
With no command line options, the config file is read correctly:
$ python test_configargparse_help.py
{'host': 'myhost', 'port': 8080}
With any other option than -h on the command line, these options override the defaults in the config file correctly too:
$ python test_configargparse_help.py -p 8888
{'host': 'myhost', 'port': 8888}
But when option -h is used on the command line, all other options us their defaults from the script:
$ python test_configargparse_help.py -h example.com
{'host': 'example.com', 'port': 80}
Hint: port should be 8080 as set in the config file.
This bug was still present. Now fixed in my fork (with a test case):
https://github.com/tbooth/ConfigArgParse/blob/devel/tests/test_issues.py