From eedb60b2962e1de1b76b7c8c3e50c0f5e9b2be91 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 21 Dec 2010 22:33:53 +0200 Subject: [PATCH] Port grab-attachments to optparse --- grab-attachments | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/grab-attachments b/grab-attachments index 4ddec36..e4c2218 100755 --- a/grab-attachments +++ b/grab-attachments @@ -18,30 +18,28 @@ # # ################################################################## +from optparse import OptionParser import os import sys + from ubuntutools.lp.libsupport import get_launchpad USAGE = "grab-attachments " def main(): - if len(sys.argv) == 1: - print >> sys.stderr, USAGE - sys.exit(1) - - if sys.argv[1] in ["--help", "-h"]: - print USAGE - sys.exit(0) + p = OptionParser('Usage: %prog [options] ') + opts, args = p.parse_args() + if len(args) < 1: + p.error('No bug numbers provided') try: launchpad = get_launchpad("ubuntu-dev-tools") - for arg in sys.argv[1:]: + for arg in args: try: number = int(arg) except: - print >> sys.stderr, "'%s' is not a valid bug number." % arg - sys.exit(1) + p.error("'%s' is not a valid bug number." % arg) b = launchpad.bugs[number]