You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a better pattern for this? There's a lot of duplicate logic, making sure both variables are the same and defaults match. Could this be a feature request to add this to argparse, maybe with a subclass?
I'm thinking something like this:
fromenvironsimportEnvArgumentParserparser=EnvArgumentParser(
env_prefix='MY_PREFIX_'# this would be neat
)
parser.add_argument('-m', '--my-option', default='value', env_name='MY_OPTION')
parser.add_argument(dest='positional', env_name='CUSTOM_NAME')
parser.add_argument(dest='many_inputs', nargs='+') # default env_name to MANY_INPUTS
Thoughts? If you think this would be useful for this library, I can try working on it. I don't know the internals of argparse very well though.
The text was updated successfully, but these errors were encountered:
The EnvArgumentParser idea seems neat, but I think it's outside the scope of this library. Would definitely be cool to see as a separate package, though. Thanks for the suggestion.
I have a use-case where I need to support both command-line arguments, as well as environment variables. This pattern ends up looking like this:
Is there a better pattern for this? There's a lot of duplicate logic, making sure both variables are the same and defaults match. Could this be a feature request to add this to argparse, maybe with a subclass?
I'm thinking something like this:
Thoughts? If you think this would be useful for this library, I can try working on it. I don't know the internals of argparse very well though.
The text was updated successfully, but these errors were encountered: