Created
August 14, 2020 06:53
-
-
Save 0xRampey/b7944250746889e8a672cb09c8ed1e04 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main(args): | |
""" Main entry point of the app """ | |
print("hello world") | |
print(args) | |
if __name__ == "__main__": | |
""" This is executed when run from the command line """ | |
parser = argparse.ArgumentParser() | |
# Required positional argument | |
parser.add_argument("arg", help="Required positional argument") | |
# Optional argument flag which defaults to False | |
parser.add_argument("-f", "--flag", action="store_true", default=False) | |
# Optional argument which requires a parameter (eg. -d test) | |
parser.add_argument("-n", "--name", action="store", dest="name") | |
# Optional verbosity counter (eg. -v, -vv, -vvv, etc.) | |
parser.add_argument( | |
"-v", | |
"--verbose", | |
action="count", | |
default=0, | |
help="Verbosity (-v, -vv, etc)") | |
# Specify output of "--version" | |
parser.add_argument( | |
"--version", | |
action="version", | |
version="%(prog)s (version {version})".format(version=__version__)) | |
args = parser.parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment