Mercurial > hg > CommandParser
annotate tests/example2.py @ 7:0abe38b2ea7b
example with mandatory arguments; b0rken
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 30 Mar 2012 10:18:34 -0700 |
parents | |
children |
rev | line source |
---|---|
7
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 from commandparser import CommandParser |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 class Example(object): |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 an example with a mandatory class argument |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 def __init__(self, foo): |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 - foo: a string |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 self.foo = foo |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 def execute(self, arg=None): |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 do something stupid |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 - arg: a pointless argument |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 """ |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 print ':'.join([self.foo, str(arg)]) |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 if __name__ == '__main__': |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 import sys |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 parser = CommandParser(Example) |
0abe38b2ea7b
example with mandatory arguments; b0rken
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 parser.invoke(sys.argv[1:]) |