Show More
@@ -1,29 +1,30 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 | pl = l.replace('-', '_') | |
11 | state[l] = d |
|
11 | map['-'+s] = map['--'+l] = pl | |
12 |
|
|
12 | state[pl] = d | |
|
13 | dt[pl] = type(d) | |||
13 | if not d is None and not callable(d): |
|
14 | if not d is None and not callable(d): | |
14 | if s: s += ':' |
|
15 | if s: s += ':' | |
15 | if l: l += '=' |
|
16 | if l: l += '=' | |
16 | if s: short = short + s |
|
17 | if s: short = short + s | |
17 | if l: long.append(l) |
|
18 | if l: long.append(l) | |
18 |
|
19 | |||
19 | opts, args = getopt.getopt(args, short, long) |
|
20 | opts, args = getopt.getopt(args, short, long) | |
20 |
|
21 | |||
21 | for opt, arg in opts: |
|
22 | for opt, arg in opts: | |
22 | if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg) |
|
23 | if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg) | |
23 | elif dt[map[opt]] is type(1): state[map[opt]] = int(arg) |
|
24 | elif dt[map[opt]] is type(1): state[map[opt]] = int(arg) | |
24 | elif dt[map[opt]] is type(''): state[map[opt]] = arg |
|
25 | elif dt[map[opt]] is type(''): state[map[opt]] = arg | |
25 | elif dt[map[opt]] is type([]): state[map[opt]].append(arg) |
|
26 | elif dt[map[opt]] is type([]): state[map[opt]].append(arg) | |
26 | elif dt[map[opt]] is type(None): state[map[opt]] = 1 |
|
27 | elif dt[map[opt]] is type(None): state[map[opt]] = 1 | |
27 |
|
28 | |||
28 | return args |
|
29 | return args | |
29 |
|
30 |
General Comments 0
You need to be logged in to leave comments.
Login now