From 1779ef7c07a26e7a9e51999066fe55ba85b945b2 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 25 Sep 2013 12:28:59 -0400 Subject: script.py template: upgrade to argparse Conflicts: code/templates/script.py --- code/templates/script.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'code') diff --git a/code/templates/script.py b/code/templates/script.py index 861ee70..d1ba416 100755 --- a/code/templates/script.py +++ b/code/templates/script.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys -import optparse +import argparse import logging log = logging.getLogger(__name__) @@ -15,21 +15,21 @@ def run(): def main(): global log - parser = optparse.OptionParser(usage= - "usage: %prog [options]\n" - "%prog --help for more info." - ) - parser.add_option("-v", "--verbose", + parser = argparse.ArgumentParser() + parser.add_argument("-v", "--verbose", default=False, help="Show more debugging statements", action="store_true") + parser.add_argument("commands", nargs='*') - (options, args) = parser.parse_args() + options = parser.parse_args() + args = options.commands if len(args) != 0: parser.error("Incorrect number of arguments") log = logging.getLogger() + log.addHandler(logging.StreamHandler()) if options.verbose: log.setLevel(logging.DEBUG) else: -- cgit v1.2.3