bw2 / ConfigArgParse

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.
MIT License
728 stars 121 forks source link

abbreviations mess up the priority order of arguments #217

Open mathisloevenich opened 3 years ago

mathisloevenich commented 3 years ago

In my scenrio I have values being set in the config file like: ignore = [errors]

Starting my script with: htcanalyze --ignore recources

will override the internal list ignore = [recources]

HOWEVER, when I only use the prefix: htcanalyze --ign recources

it will result in ignore = [errors].

In this case the config values will not be overwritten, which will result in different user experiences cause no error is thrown due to the ability of argparse on matching prefixes.

This is related to the issue of my project: https://github.com/psyinfra/HTCAnalyze/issues/90

bw2 commented 3 years ago

This is a bug. The problem is at least partly due to https://github.com/bw2/ConfigArgParse/blob/master/configargparse.py#L1032

checking for exact matches without first converting prefixes to their corresponding full option names. A PR to fix this would be appreciated.

bw2 commented 3 years ago

Replacing https://github.com/bw2/ConfigArgParse/blob/d8eb8731dfe32125b83d14b9332990af0eb072cc/configargparse.py#L1058-L1060 with

return any(
        arg_name.startswith(potential_arg) for potential_arg in potential_command_line_args for arg_name in arg_names
    )

should fix this, but argparse has since added an allow_abbrev arg, so will need to add handling for that before this can be fixed.