-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
68 lines (42 loc) · 1.41 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
59
60
61
62
63
64
65
66
67
import lightargs
import sys
def _doA(a1,a2):
print ("A:",a1,a2)
def _doB(b1,b2,b3):
print ("B:",b1,b2,b3)
def _sum(value1,value2):
print ("sum:",float(value1)+float(value2))
def _hidden():
print ("called hidden function !")
lightargs.set_usage("welcome to lightargs example !")
lightargs.add( "doA",
_doA,
nb_args=2,
args_labels=("a1","a2"),
defaults=("default_a1","default_a2"),
man="print 'A:' followed by a1 and a2 arguments",
category="example")
lightargs.add( "doB",
_doB,
nb_args=3,
args_labels=("b1","b2","b3"),
defaults=("default_b1","default_b2","default_b3"),
man="print 'B:' followed by b1, b2 and b3 arguments",
category="example")
lightargs.add("sum",
_sum,
nb_args=2,
man="print the sum of the two arguments",
category="utils")
lightargs.add("hidden",
_hidden,
nb_args=0,
man="because in category 'hidden', this argument will not shown up in the doc",
category="hidden")
if __name__ == "__main__":
try:
lightargs.execute(sys.argv[1:])
except lightargs.WrongParameters as e:
print (str(e))
except lightargs.UnknownArgument as e:
print (str(e))