Mathis Lövenich

Results 11 comments of Mathis Lövenich

I recognized the following behaviour: _/etc/conf/app_config.ini_ ``` value = 1 ignore-value = 2 ``` _./app_config.txt_ ``` value = 100 ``` parse_args() returns: `Namespace(value=100, ignore_value=1)` But it would be nice to...

and then obviously it would be nice to know which one was used (if there are multiple config files found)

If you work with `choices`, it will mess up the code. A workaround for this is to add an empty string to `choices` `choices.append([''])`

If there is no particular reason for this behaviour it would be nice to fix this, even if it's not necessarily a bug.

With the new version 1.5.3 this is no longer working. It worked on 1.2.3

We can simply fix this with `nargs="*"`, but obviously this would allow to have flags with no effects

An easy work-around to this is: ``` class MyArgumentParser(ArgumentParser): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def set_default_config_paths(self, config_paths): self._default_config_files = config_paths ``` ``` parser = MyArgumentParser() parser.add_argument("--ignore-config", action="store_true") args =...

But I would recomment to add a flag to the `add_argument` method.

Be aware that this messes up the help description. Rather use: ``` args=sys.argv[1:] parser = MyArgumentParser() parser.add_argument("--ignore-config", action="store_true") if "-h" in args or "--help" in args: parser.set_default_config_paths(["/etc/conf/app_config.ini"]) parser.parse_args(["-h"]) # exit...

In my case this is working for me: ``` class CLIArgumentParser(ArgumentParser): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def set_default_config_paths(self, config_paths): self._default_config_files = config_paths def get_arguments(self, args): # add config paths...