-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
executable file
·58 lines (40 loc) · 1.17 KB
/
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
51
52
53
54
55
56
57
58
#!/usr/bin/env python
from parsable import parsable
import sys
# This optional line creates a local parser
# that won't leak into modules that import this module.
parsable = parsable.Parsable()
@parsable
def example_command(required_arg, optional_int=1, optional_string='asdf'):
'An example command that prints its arguments'
assert isinstance(required_arg, str)
assert isinstance(optional_int, int)
assert isinstance(optional_string, str)
print(required_arg, optional_int, optional_string)
@parsable
def another_command():
'No arguments on this one'
@parsable
def print_all_strings(*args):
'Example of variable number of arguments'
print('len(args) = %i' % len(args))
print('args:')
for arg in args:
assert isinstance(arg, str)
print(' {0}'.format(arg))
global_value = True
@parsable
def __set_value_to_false():
'Example of command-as-option'
global global_value
global_value = False
@parsable
def twice(*args):
'Run a command twice'
argv = [sys.argv[0]] + list(args)
print('first time:')
parsable(argv)
print('second time:')
parsable(argv)
if __name__ == '__main__':
parsable()