fancyopts.py
27 lines
| 769 B
| text/x-python
|
PythonLexer
/ mercurial / fancyopts.py
|
r560 | import os, getopt | ||
|
r0 | |||
|
r596 | def fancyopts(args, options, state): | ||
|
r0 | long=[] | ||
short='' | ||||
map={} | ||||
dt={} | ||||
for s, l, d, c in options: | ||||
map['-'+s] = map['--'+l]=l | ||||
state[l] = d | ||||
dt[l] = type(d) | ||||
|
r515 | if not d is None and not callable(d): s, l=s+':', l+'=' | ||
|
r0 | if s: short = short + s | ||
if l: long.append(l) | ||||
|
r293 | opts, args = getopt.getopt(args, short, long) | ||
|
r0 | |||
for opt, arg in opts: | ||||
|
r293 | if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg) | ||
|
r0 | elif dt[map[opt]] is type(1): state[map[opt]] = int(arg) | ||
elif dt[map[opt]] is type(''): state[map[opt]] = arg | ||||
elif dt[map[opt]] is type([]): state[map[opt]].append(arg) | ||||
elif dt[map[opt]] is type(None): state[map[opt]] = 1 | ||||
|
r209 | |||
|
r0 | return args | ||