Created
July 6, 2022 15:37
-
-
Save toloco/224cc171c0c8926244266e55c3d7ba5d to your computer and use it in GitHub Desktop.
Argparser python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
def parse_args(): | |
log_levels = { | |
"info": logging.INFO, | |
"debug": logging.DEBUG, | |
"warning": logging.WARNING, | |
} | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--s3-fixture", | |
type=str, | |
default="s3://foo/bar/baz.tgz", | |
) | |
parser.add_argument( | |
"--env", type=str.lower, choices=environment_configs(), default="integ" | |
) | |
parser.add_argument("--max-retry", type=int, default=None) | |
parser.add_argument( | |
"--formats", | |
type=str, | |
default=None, | |
help="Filter by format(s)", | |
nargs="*", | |
) | |
parser.add_argument( | |
"--disable-feature", | |
dest="feature", | |
action="store_false", | |
help="disable feature", | |
) | |
parser.add_argument( | |
"--enable-feature", | |
dest="feature", | |
action="store_true", | |
help="Enable feature (default)", | |
) | |
parser.set_defaults(feature=True) | |
parser.add_argument("--log-level", type=str, choices=log_levels, default="info") | |
return parser.parse_args() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment