hg help improvements
-----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-----
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -77,6 +77,17 @@ def help(ui, cmd=None):
try:
i = find(cmd)
ui.write("%s\n\n" % i[2])
+
+ if i[1]:
+ for s, l, d, c in i[1]:
+ opt=' '
+ if s: opt = opt + '-' + s + ' '
+ if l: opt = opt + '--' + l + ' '
+ if d: opt = opt + '(' + str(d) + ')'
+ ui.write(opt, "\n")
+ if c: ui.write(' %s\n' % c)
+ ui.write("\n")
+
ui.write(i[0].__doc__, "\n")
except UnknownCommand:
ui.warn("hg: unknown command %s\n" % cmd)
@@ -603,7 +614,12 @@ def dispatch(args):
signal.signal(signal.SIGTERM, catchterm)
cmdoptions = {}
- args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
+ try:
+ args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
+ except fancyopts.getopt.GetoptError, inst:
+ u.warn("hg %s: %s\n" % (cmd, inst))
+ help(u, cmd)
+ sys.exit(-1)
if cmd not in norepo.split():
repo = hg.repository(ui = u)
@@ -627,7 +643,8 @@ def dispatch(args):
tb = traceback.extract_tb(sys.exc_info()[2])
if len(tb) > 2: # no
raise
- raise
+ u.debug(inst, "\n")
u.warn("%s: invalid arguments\n" % i[0].__name__)
- u.warn("syntax: %s\n" % i[2])
+ help(u, cmd)
sys.exit(-1)
+
--- a/mercurial/fancyopts.py
+++ b/mercurial/fancyopts.py
@@ -6,48 +6,25 @@ def fancyopts(args, options, state, synt
map={}
dt={}
- def help(state, opt, arg, options=options, syntax=syntax):
- print "Usage: ", syntax
-
- for s, l, d, c in options:
- opt=' '
- if s: opt = opt + '-' + s + ' '
- if l: opt = opt + '--' + l + ' '
- if d: opt = opt + '(' + str(d) + ')'
- print opt
- if c: print ' %s' % c
- sys.exit(0)
-
- if len(args) < minlen:
- help(state, None, args)
-
- options=[('h', 'help', help, 'Show usage info')] + options
-
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 type(d) is type(help): s, l=s+':', l+'='
+ 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
- try:
- opts, args = getopt.getopt(args, short, long)
- except getopt.GetoptError:
- help(state, None, args)
- sys.exit(-1)
+ opts, args = getopt.getopt(args, short, long)
for opt, arg in opts:
- if dt[map[opt]] is type(help): state[map[opt]](state,map[opt],arg)
+ 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
- del state["help"]
-
return args