Mercurial > hg > CommandParser
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 6:48aa5a9ef7e1 | 7:0abe38b2ea7b |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 from commandparser import CommandParser | |
| 4 | |
| 5 | |
| 6 class Example(object): | |
| 7 """ | |
| 8 an example with a mandatory class argument | |
| 9 """ | |
| 10 | |
| 11 def __init__(self, foo): | |
| 12 """ | |
| 13 - foo: a string | |
| 14 """ | |
| 15 self.foo = foo | |
| 16 | |
| 17 def execute(self, arg=None): | |
| 18 """ | |
| 19 do something stupid | |
| 20 - arg: a pointless argument | |
| 21 """ | |
| 22 print ':'.join([self.foo, str(arg)]) | |
| 23 | |
| 24 if __name__ == '__main__': | |
| 25 import sys | |
| 26 parser = CommandParser(Example) | |
| 27 parser.invoke(sys.argv[1:]) |
