Module utilities.env_var_action

EnvVarAction class definition

Classes

class EnvVarAction (option_strings, dest, default=None, type=None, **kwargs)

Custom argparse action to override command line args with environment variable values if environment variables have been set. To work, the environment variable name must equal (cmd line arg namespace name).upper(). For example:

    cmd line arg        namespace name      env var name
    ------------        --------------      ------------
    --log-console       log_console         LOG_CONSOLE
    --aws-s3-bucket     aws_s3_bucket       AWS_S3_BUCKET

For boolean type args, this action works similarly to the 'store_true' built-in action, i.e. the cmd line arg functions as a switch to set the namespace value to True (unless the environment variable is defined in which case the env value will be used).

Ancestors

  • argparse.Action
  • argparse._AttributeHolder