ConfigArgParse icon indicating copy to clipboard operation
ConfigArgParse copied to clipboard

Command line arguments do not override config file values

Open blondtrip opened this issue 9 years ago • 2 comments

If the following scheme is used and arguments are specified both in a config-file and from command line the correct priority is not always followed. E.g. if we specify --testarg in the config-file and --no-testarg in the command line the result will be testarg=True. This is due to the fact that --testarg and --no-testarg are treated as distinct arguments even if they refer to the same destination.

parser.add(
        '--testarg', dest='testarg', default=None, required=False,
        action='store_true'
    )
parser.add(
        '--no-testarg', dest='testarg', default=None, required=False,
        action='store_false'
    )

blondtrip avatar Apr 19 '16 13:04 blondtrip

This could be fixed by modifying calls to already_on_command_line(..) to pass in a list of action.option_strings not just for the current action, but for all actions that have the same dest.

bw2 avatar Sep 05 '16 01:09 bw2

A pull request with tests would be appreciated.

bw2 avatar Sep 05 '16 01:09 bw2