~yasumoto7/five-a-day/icon_countdown

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2008 (C) Canonical Ltd.

from gettext import gettext as _

import sys

# TODO: use optparse.Optionparser!? I've used this already in my branch (blueyed)
#       See http://bazaar.launchpad.net/~blueyed/five-a-day/five-a-day-lazy-remote/revision/48
#       In general, parse_args should already validate bug arguments and some object should get
#       used to store parsed options/actions, so that other methods do not have to e.g.
#       filter "-f" and "--force" out!
# TODO: Option "-n"/"--no-remote" to never update/commit the branch

USAGE = \
_("""5-a-day --add <bug numbers>     add <bug numbers> to your 5-a-day
    -f | --force                force commit to the remote branch

5-a-day --update                update ~/.signature with the bugs you've worked on
    --html                      update ~/.signature and print HTML signature
    --yesterday                 update ~/.signature with yesterdays bugs
    
5-a-day --add-tag <tag>         tag subsequent bugs with <tag>
5-a-day --remove-tag <tag>      remove <tag> from your tag list
5-a-day --show-tag(s)           show current tag(s)""")

def parse_args():
    args = sys.argv
    cmd = args[0]
    
    if len(args)>1 and args[1] in ["--help", "-h"]:
        print USAGE
        sys.exit(0)
    
    a = list()
    if cmd.endswith("update-signature"):
        a.append("--update")
        if args and "--html" in args:
            a.append("--html")
        if args and "--yesterday" in args:
            a.append("--yesterday")

    if cmd.endswith("add-5-a-day"):
        a.append("--add")
        if args[1:]:
            a.extend(args[1:])
        

    if a:
        print _("Calling: 5-a-day %s") % " ".join(a)
    else:
        a = args[1:]

    if (not a) or a[0] not in ["--update", "--add", "--remove-tag", 
                               "--add-tag", "--show-tag", "--show-tags", 
                               "--show-team", "--add-team", "--remove-team",
                               "--show-teams"]:
        print >> sys.stderr, USAGE
        sys.exit(1)

    if a[0] == "--add" and len(a) == 1: # "--add -f" is allowed
        print >> sys.stderr, USAGE
        sys.exit(1)

    if a[0] in ["--add", "--remove-tag"] and len(a) == 1:
        print >> sys.stderr, USAGE
        sys.exit(1)

    return a