bw2 / ConfigArgParse

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

Add support for no_config_file=True option in the add_argument() function #229

Closed tristanlatr closed 3 years ago

tristanlatr commented 3 years ago

The docs of the new option read as follows:

no_config_file (bool): If True, this prevents the argument to be settable with 
            a config file. It will raise an exception if one tries to set this
            option from a file.

I think it's a necessary thing to exclude some option from the configuration file sometime!

tristanlatr commented 3 years ago

Maybe it would be good to fix #46 at the same time?

bw2 commented 3 years ago

Could you say more about why you want this behavior? It seems to me like a very rare use-case and might be better-handled outside the library - by adding a getter for the self. _source_to_settings array, and checking that to throw this error. What do you think?

Also, calling the argument "no_config_file" seems confusing to me - as the wording makes me think it means something like "use this option when the config file is missing". Could you call it something like "forbidden_in_config_file" or "forbid_setting_via_config_file"?

bw2 commented 3 years ago

I appreciate you adding types to some of the docs. For the no_config_file option, are you just trying to detect / help users figure out that they shouldn't put "help=True" or "version=True" in a config file? It seems like one use for "no_config_file" would be to exclude certain options from being written out via the "is_write_out_config_file_arg" arg.

tristanlatr commented 3 years ago

I agree with you that a name like "forbidden_in_config_file" is more explicit.

This new option is indeed to prevent users to set options like --versions from the config file, is there another way to do that that I'm not aware ?

Thanks

bw2 commented 3 years ago

Sorry I don't see this as a broadly useful feature. Perhaps we can revisit if additional people want this.