Last active
July 20, 2018 16:04
-
-
Save kincl/9dd8af29848f269e2065f735148a45f9 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Module Docstring | |
""" | |
__author__ = "Your Name" | |
__version__ = "0.1.0" | |
import argparse | |
import logging | |
LOG = logging.getLogger(__name__) | |
def main(args): | |
""" Main entry point of the app """ | |
print("hello world") | |
LOG.info('test %s', 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") | |
parser.add_argument( | |
"-v", | |
"--verbose", | |
action="count", | |
default=0, | |
help="Verbosity (-v, -vv)") | |
parser.add_argument( | |
"--version", | |
action="version", | |
version="%(prog)s (version {version})".format(version=__version__)) | |
args = parser.parse_args() | |
# Set up clean logging to stderr | |
log_levels = [logging.ERROR, logging.INFO, logging.DEBUG] | |
args.verbose = min(args.verbose, len(log_levels) - 1) | |
args.verbose = max(args.verbose, 0) | |
logging.basicConfig(level=log_levels[args.verbose], | |
format='%(levelname)s: %(message)s') | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment