##// END OF EJS Templates
Fix option parsing bug for empty short options
mpm@selenic.com -
r959:0aaeee51 default
parent child Browse files
Show More
@@ -1,27 +1,29 b''
1 import getopt
1 import getopt
2
2
3 def fancyopts(args, options, state):
3 def fancyopts(args, options, state):
4 long=[]
4 long=[]
5 short=''
5 short=''
6 map={}
6 map={}
7 dt={}
7 dt={}
8
8
9 for s, l, d, c in options:
9 for s, l, d, c in options:
10 map['-'+s] = map['--'+l]=l
10 map['-'+s] = map['--'+l]=l
11 state[l] = d
11 state[l] = d
12 dt[l] = type(d)
12 dt[l] = type(d)
13 if not d is None and not callable(d): s, l=s+':', l+'='
13 if not d is None and not callable(d):
14 if s: s += ':'
15 if l: l += '='
14 if s: short = short + s
16 if s: short = short + s
15 if l: long.append(l)
17 if l: long.append(l)
16
18
17 opts, args = getopt.getopt(args, short, long)
19 opts, args = getopt.getopt(args, short, long)
18
20
19 for opt, arg in opts:
21 for opt, arg in opts:
20 if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg)
22 if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg)
21 elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
23 elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
22 elif dt[map[opt]] is type(''): state[map[opt]] = arg
24 elif dt[map[opt]] is type(''): state[map[opt]] = arg
23 elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
25 elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
24 elif dt[map[opt]] is type(None): state[map[opt]] = 1
26 elif dt[map[opt]] is type(None): state[map[opt]] = 1
25
27
26 return args
28 return args
27
29
General Comments 0
You need to be logged in to leave comments. Login now