Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 293:11d64332a1cb
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-----
author | mpm@selenic.com |
---|---|
date | Wed, 08 Jun 2005 20:11:57 -0800 |
parents | 07c6cb9fd1c5 |
children | f8d56da6ac8f |
comparison
equal
deleted
inserted
replaced
292:09364bcebdf0 | 293:11d64332a1cb |
---|---|
75 '''show help for a given command or all commands''' | 75 '''show help for a given command or all commands''' |
76 if cmd: | 76 if cmd: |
77 try: | 77 try: |
78 i = find(cmd) | 78 i = find(cmd) |
79 ui.write("%s\n\n" % i[2]) | 79 ui.write("%s\n\n" % i[2]) |
80 | |
81 if i[1]: | |
82 for s, l, d, c in i[1]: | |
83 opt=' ' | |
84 if s: opt = opt + '-' + s + ' ' | |
85 if l: opt = opt + '--' + l + ' ' | |
86 if d: opt = opt + '(' + str(d) + ')' | |
87 ui.write(opt, "\n") | |
88 if c: ui.write(' %s\n' % c) | |
89 ui.write("\n") | |
90 | |
80 ui.write(i[0].__doc__, "\n") | 91 ui.write(i[0].__doc__, "\n") |
81 except UnknownCommand: | 92 except UnknownCommand: |
82 ui.warn("hg: unknown command %s\n" % cmd) | 93 ui.warn("hg: unknown command %s\n" % cmd) |
83 sys.exit(0) | 94 sys.exit(0) |
84 else: | 95 else: |
601 sys.exit(1) | 612 sys.exit(1) |
602 | 613 |
603 signal.signal(signal.SIGTERM, catchterm) | 614 signal.signal(signal.SIGTERM, catchterm) |
604 | 615 |
605 cmdoptions = {} | 616 cmdoptions = {} |
606 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | 617 try: |
618 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | |
619 except fancyopts.getopt.GetoptError, inst: | |
620 u.warn("hg %s: %s\n" % (cmd, inst)) | |
621 help(u, cmd) | |
622 sys.exit(-1) | |
607 | 623 |
608 if cmd not in norepo.split(): | 624 if cmd not in norepo.split(): |
609 repo = hg.repository(ui = u) | 625 repo = hg.repository(ui = u) |
610 d = lambda: i[0](u, repo, *args, **cmdoptions) | 626 d = lambda: i[0](u, repo, *args, **cmdoptions) |
611 else: | 627 else: |
625 except TypeError, inst: | 641 except TypeError, inst: |
626 # was this an argument error? | 642 # was this an argument error? |
627 tb = traceback.extract_tb(sys.exc_info()[2]) | 643 tb = traceback.extract_tb(sys.exc_info()[2]) |
628 if len(tb) > 2: # no | 644 if len(tb) > 2: # no |
629 raise | 645 raise |
630 raise | 646 u.debug(inst, "\n") |
631 u.warn("%s: invalid arguments\n" % i[0].__name__) | 647 u.warn("%s: invalid arguments\n" % i[0].__name__) |
632 u.warn("syntax: %s\n" % i[2]) | 648 help(u, cmd) |
633 sys.exit(-1) | 649 sys.exit(-1) |
650 |