forked from fritzo/parsable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
executable file
·50 lines (33 loc) · 906 Bytes
/
example.py
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
#!/usr/bin/python
import parsable
@parsable.command
def example_command(required_arg, optional_int=1, optional_string='asdf'):
'an example command that prints its arguments'
print required_arg
print optional_int
print optional_string
@parsable.command
def another_command():
'no arguments on this one'
@parsable.command
def print_all_strings(*args):
'example of variable number of arguments'
print 'len(args) = %i' % len(args)
print 'args:'
for arg in args:
print ' %s' % arg
global_value = True
@parsable.command
def __set_value_to_false():
'example of command-as-option'
global global_value
global_value = False
@parsable.command
def twice(*args):
'run a command twice'
print 'first time:'
parsable.dispatch(args)
print 'second time:'
parsable.dispatch(args)
if __name__ == '__main__':
parsable.dispatch()