Skip to content

Instantly share code, notes, and snippets.

@qheuristics
Forked from elmotec/bootstrap_cmdline.py
Created February 15, 2018 20:32
Show Gist options
  • Save qheuristics/56e9190ea388fe91f1768559be1b77aa to your computer and use it in GitHub Desktop.
Save qheuristics/56e9190ea388fe91f1768559be1b77aa to your computer and use it in GitHub Desktop.

Revisions

  1. elmotec revised this gist May 24, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ def parse_command_line(argv):
    def main():
    """Main program. Sets up logging and do some work."""
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
    format='%(name)s (%(levelname)s): %(message)s'))
    format='%(name)s (%(levelname)s): %(message)s')
    try:
    arguments = parse_command_line(sys.argv)
    # Do something with arguments.
  2. elmotec revised this gist May 24, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -29,9 +29,8 @@ def parse_command_line(argv):
    parser.add_argument('-o', metavar="output",
    type=argparse.FileType('w'), default=sys.stdout,
    help="redirect output to a file")
    #parser.add_argument('input', metavar="input",
    ## nargs='+', # argparse.REMAINDER,
    #help="input if any...")
    parser.add_argument('input', metavar="input", nargs='+',
    argparse.REMAINDER, help="input if any...")
    arguments = parser.parse_args(argv[1:])
    # Sets log level to WARN going more verbose for each new -v.
    log.setLevel(max(3 - arguments.verbose_count, 0) * 10)
  3. elmotec revised this gist Nov 16, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,8 @@ def main():
    try:
    arguments = parse_command_line(sys.argv)
    # Do something with arguments.
    except KeyboardInterrupt:
    log.error('Program interrupted!')
    finally:
    logging.shutdown()

  4. @elmotec elmotec revised this gist Nov 25, 2013. 1 changed file with 8 additions and 11 deletions.
    19 changes: 8 additions & 11 deletions bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,8 @@
    #!/usr/bin/env python
    # encoding: utf-8

    """Minimal python commad line."""

    __version__ = "1.0"

    """Minimal python commad line."""

    import sys
    import argparse
    @@ -15,32 +14,32 @@


    def parse_command_line(argv):
    """Parses command line argument. See -h option
    """Parse command line argument. See -h option
    Arguments:
    argv: arguments on the command line must include caller file name.
    :param argv: arguments on the command line must include caller file name.
    """
    formatter_class = argparse.RawDescriptionHelpFormatter
    parser = argparse.ArgumentParser(description=module,
    formatter_class=formatter_class)
    parser.add_argument("--version", action="version",
    version="%(prog)s {}".format(__version__))
    version="%(prog)s {}".format(__version__))
    parser.add_argument("-v", "--verbose", dest="verbose_count",
    action="count", default=0,
    help="increases log verbosity for each occurence.")
    parser.add_argument('-o', metavar="output",
    type=argparse.FileType('w'), default=sys.stdout,
    help="redirect output to a file")
    #parser.add_argument('input', metavar="input",
    ## nargs='+', # argparse.REMAINDER,
    #help="input if any...")
    ## nargs='+', # argparse.REMAINDER,
    #help="input if any...")
    arguments = parser.parse_args(argv[1:])
    # Sets log level to WARN going more verbose for each new -v.
    log.setLevel(max(3 - arguments.verbose_count, 0) * 10)
    return arguments


    def main():
    """Main program. Sets up logging and do some work."""
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
    format='%(name)s (%(levelname)s): %(message)s'))
    try:
    @@ -49,7 +48,5 @@ def main():
    finally:
    logging.shutdown()


    if __name__ == "__main__":
    sys.exit(main())

  5. elmotec revised this gist Jul 17, 2013. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,9 @@
    def parse_command_line(argv):
    """Parses command line argument. See -h option
    Arguments:
    argv: arguments on the command line must include caller file name.
    """
    module = argv[0]
    Arguments:
    argv: arguments on the command line must include caller file name.
    """
    formatter_class = argparse.RawDescriptionHelpFormatter
    parser = argparse.ArgumentParser(description=module,
    formatter_class=formatter_class)
  6. elmotec revised this gist Jul 17, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions bootstrap_cmdline.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,8 @@
    import logging


    log = logging.getLogger(__name__)
    module = sys.modules['__main__'].__file__
    log = logging.getLogger(module)


    def parse_command_line(argv):
    @@ -41,7 +42,8 @@ def parse_command_line(argv):


    def main():
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
    format='%(name)s (%(levelname)s): %(message)s'))
    try:
    arguments = parse_command_line(sys.argv)
    # Do something with arguments.
  7. elmotec renamed this gist Jul 16, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. elmotec created this gist Jul 16, 2013.
    54 changes: 54 additions & 0 deletions bootstrap_python.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/usr/bin/env python

    """Minimal python commad line."""

    __version__ = "1.0"


    import sys
    import argparse
    import logging


    log = logging.getLogger(__name__)


    def parse_command_line(argv):
    """Parses command line argument. See -h option
    Arguments:
    argv: arguments on the command line must include caller file name.
    """
    module = argv[0]
    formatter_class = argparse.RawDescriptionHelpFormatter
    parser = argparse.ArgumentParser(description=module,
    formatter_class=formatter_class)
    parser.add_argument("--version", action="version",
    version="%(prog)s {}".format(__version__))
    parser.add_argument("-v", "--verbose", dest="verbose_count",
    action="count", default=0,
    help="increases log verbosity for each occurence.")
    parser.add_argument('-o', metavar="output",
    type=argparse.FileType('w'), default=sys.stdout,
    help="redirect output to a file")
    #parser.add_argument('input', metavar="input",
    ## nargs='+', # argparse.REMAINDER,
    #help="input if any...")
    arguments = parser.parse_args(argv[1:])
    # Sets log level to WARN going more verbose for each new -v.
    log.setLevel(max(3 - arguments.verbose_count, 0) * 10)
    return arguments


    def main():
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    try:
    arguments = parse_command_line(sys.argv)
    # Do something with arguments.
    finally:
    logging.shutdown()


    if __name__ == "__main__":
    sys.exit(main())