bw2 / ConfigArgParse

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

Unexpected behaviour of `convert_item_to_command_line_arg` for custom `argparse` actions #249

Closed ge0pan closed 2 years ago

ge0pan commented 2 years ago

We're using the latest ConfigArgParse (1.5.2) with python 3.7 and trying to add our custom argparse action similarly to the BooleanOptionalAction.

In our case, if we have argument '--enable-feature', '--disable-feature', action=CustomBooleanOptionalAction and we have enable-feature in the config file, convert_item_to_command_line_arg converts it to --disable-feature=true. For one, it is not correct. Additionally, argparse will raise an exception because this action does not expect argument value (ignored explicit argument true).

This issue is similar with what is mentioned in #248. But in our case we want support for custom actions.

As a hacky solution we monkeypatched convert_item_to_command_line_arg to return f'--{key}'. Maybe it is not as bad of an idea considering that all of the config keys are checked up to this point and are guaranteed to be valid.

bw2 commented 2 years ago

I've just published v1.5.3 which incorporates PR #248 . Hopefully this fixes the issue.