Merge lp:~jameinel/hydrazine/arg-parsing into lp:hydrazine

Proposed by John A Meinel
Status: Merged
Approved by: Martin Pool
Approved revision: 71
Merged at revision: 73
Proposed branch: lp:~jameinel/hydrazine/arg-parsing
Merge into: lp:hydrazine
Diff against target: 36 lines (+7/-8)
1 file modified
feed-pqm (+7/-8)
To merge this branch: bzr merge lp:~jameinel/hydrazine/arg-parsing
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+28669@code.launchpad.net

Description of the change

This fixes up some of the argument parsing.

Basically, there was code that said "if you have != 1 argument, abort", which doesn't work when you can supply stuff like --queued.

It then always used 'argv[1]' rather than using 'args[0]'. (So if you did 'feed-pqm --queued' it would parse the queued request, and then try and look at the --queued project in Launchpad.)

This should fix it up, and changes how it displays usage, etc. as well.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'feed-pqm'
2--- feed-pqm 2010-06-23 01:33:23 +0000
3+++ feed-pqm 2010-06-28 19:15:47 +0000
4@@ -163,13 +163,18 @@
5
6
7 def main(argv):
8- parser = optparse.OptionParser()
9+ parser = optparse.OptionParser('%prog [options] PROJECT\n\n'
10+ ' PROJECT is the launchpad project to inspect (eg bzr)')
11 parser.add_option('--nomail', help="Do not send email commands", action="store_true", default=False)
12 parser.add_option('--queued', help="Examine already queued proposals", action="store_true", default=False)
13 opts, args = parser.parse_args()
14+ if len(args) != 1:
15+ parser.print_usage()
16+ return 1
17+ project = args[0]
18 bzrlib_setup()
19 launchpad = hydrazine.create_session()
20- project = launchpad.projects[argv[1]]
21+ project = launchpad.projects[project]
22 i = 0
23 find_status = ['Approved']
24 if opts.queued:
25@@ -217,11 +222,5 @@
26 print "No remaining merge proposals matching status %r?" % find_status
27 return 0
28
29-def usage():
30- print "feed-pqm <project-name>"
31-
32 if __name__ == '__main__':
33- if len(sys.argv) != 2:
34- usage()
35- sys.exit(1)
36 sys.exit(main(sys.argv))

Subscribers

People subscribed via source and target branches

to all changes: