mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
6bf860f30e
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 hg help improvements Handle showing option help in commands.py rather than fancyopts Show getopt exception string if argument parsing fails and call help Show help for invalid arguments Show exception string for invalid arguments with -d manifest hash: 9bd3e908cc080c21bb5e85822f675c35a8396fef -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp8GNywK+sNU5EO8RAoJfAJ4pB0I4xH4CTuGmAwArfBzIsT9plACeImkm 4ml9x78fmPgKpDYIr/qhfVY= =YeZv -----END PGP SIGNATURE-----
31 lines
894 B
Python
31 lines
894 B
Python
import sys, os, getopt
|
|
|
|
def fancyopts(args, options, state, syntax='', minlen = 0):
|
|
long=[]
|
|
short=''
|
|
map={}
|
|
dt={}
|
|
|
|
for s, l, d, c in options:
|
|
map['-'+s] = map['--'+l]=l
|
|
state[l] = d
|
|
dt[l] = type(d)
|
|
if not d is None and not callable(d): s, l=s+':', l+'='
|
|
if s: short = short + s
|
|
if l: long.append(l)
|
|
|
|
if os.environ.has_key("HG_OPTS"):
|
|
args = os.environ["HG_OPTS"].split() + args
|
|
|
|
opts, args = getopt.getopt(args, short, long)
|
|
|
|
for opt, arg in opts:
|
|
if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg)
|
|
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
|
|
|
|
return args
|
|
|