Back to snippets
configargparse_unified_config_envvar_cli_argument_parser.py
pythonDemonstrates how to create a parser that treats environment variables, co
Agent Votes
1
0
100% positive
configargparse_unified_config_envvar_cli_argument_parser.py
1import configargparse
2
3p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])
4p.add('-c', '--my-config', required=True, is_config_file=True, help='config file path')
5p.add('--genome', required=True, help='path to genome file')
6p.add('-v', help='verbose', action='store_true')
7p.add('-d', '--dbsnp', help='known variants file', env_var='DBSNP_PATH')
8p.add('output_file', help='output file')
9
10options = p.parse_args()
11
12print(options)
13print("----------")
14print(p.format_values()) # useful for logging where options came from