##// END OF EJS Templates
fancyopts: Copy list arguments in command table before modifying....
Thomas Arendsen Hein -
r5093:88803a69 default
parent child Browse files
Show More
@@ -1,32 +1,35 b''
1 1 import getopt
2 2
3 3 def fancyopts(args, options, state):
4 4 long = []
5 5 short = ''
6 6 map = {}
7 7 dt = {}
8 8
9 9 for s, l, d, c in options:
10 10 pl = l.replace('-', '_')
11 11 map['-'+s] = map['--'+l] = pl
12 state[pl] = d
12 if isinstance(d, list):
13 state[pl] = d[:]
14 else:
15 state[pl] = d
13 16 dt[pl] = type(d)
14 17 if (d is not None and d is not True and d is not False and
15 18 not callable(d)):
16 19 if s: s += ':'
17 20 if l: l += '='
18 21 if s: short = short + s
19 22 if l: long.append(l)
20 23
21 24 opts, args = getopt.getopt(args, short, long)
22 25
23 26 for opt, arg in opts:
24 27 if dt[map[opt]] is type(fancyopts): state[map[opt]](state, map[opt], arg)
25 28 elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
26 29 elif dt[map[opt]] is type(''): state[map[opt]] = arg
27 30 elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
28 31 elif dt[map[opt]] is type(None): state[map[opt]] = True
29 32 elif dt[map[opt]] is type(False): state[map[opt]] = True
30 33
31 34 return args
32 35
General Comments 0
You need to be logged in to leave comments. Login now