Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 592:74175ce83378
Restructure option handling
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Restructure option handling
This allows global options to appear before or after the command name
Also includes a patch from Andrew Thompson <andrewkt@aktzero.com> to
catch invalid global options.
manifest hash: 2a1285c0caf04ae79dca10cb899d183d84a6f3d4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCx80cywK+sNU5EO8RApJSAJ9U6ijOIbMDAd4lcahY6dXCTPcsNACeKuNT
iVhCp9IvacwwuHjAFXsLJEQ=
=Q9Qe
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 03 Jul 2005 03:33:48 -0800 |
parents | eb46971fc57f |
children | ca3c499e94c6 |
comparison
equal
deleted
inserted
replaced
591:eb46971fc57f | 592:74175ce83378 |
---|---|
976 | 976 |
977 def run(): | 977 def run(): |
978 sys.exit(dispatch(sys.argv[1:])) | 978 sys.exit(dispatch(sys.argv[1:])) |
979 | 979 |
980 def dispatch(args): | 980 def dispatch(args): |
981 signal.signal(signal.SIGTERM, catchterm) | |
982 | |
983 def get_ui(): | |
984 return ui.ui(options["verbose"], options["debug"], options["quiet"], | |
985 not options["noninteractive"]) | |
986 | |
981 options = {} | 987 options = {} |
982 opts = [('v', 'verbose', None, 'verbose'), | 988 opts = [('v', 'verbose', None, 'verbose'), |
983 ('', 'debug', None, 'debug'), | 989 ('', 'debug', None, 'debug'), |
984 ('q', 'quiet', None, 'quiet'), | 990 ('q', 'quiet', None, 'quiet'), |
985 ('', 'profile', None, 'profile'), | 991 ('', 'profile', None, 'profile'), |
987 ('', 'traceback', None, 'print traceback on exception'), | 993 ('', 'traceback', None, 'print traceback on exception'), |
988 ('y', 'noninteractive', None, 'run non-interactively'), | 994 ('y', 'noninteractive', None, 'run non-interactively'), |
989 ('', 'version', None, 'output version information and exit'), | 995 ('', 'version', None, 'output version information and exit'), |
990 ] | 996 ] |
991 | 997 |
992 args = fancyopts.fancyopts(args, opts, options, | 998 try: |
993 'hg [options] <command> [options] [files]') | 999 args = fancyopts.fancyopts(args, opts, options, |
1000 'hg [options] <command> [options] [files]') | |
1001 except fancyopts.getopt.GetoptError, inst: | |
1002 u = ui.ui() | |
1003 u.warn("hg: %s\n" % (inst)) | |
1004 sys.exit(-1) | |
994 | 1005 |
995 if not args: | 1006 if not args: |
996 cmd = "help" | 1007 cmd = "help" |
997 else: | 1008 else: |
998 cmd, args = args[0], args[1:] | 1009 cmd, args = args[0], args[1:] |
999 | 1010 |
1000 u = ui.ui(options["verbose"], options["debug"], options["quiet"], | |
1001 not options["noninteractive"]) | |
1002 | |
1003 if options["version"]: | 1011 if options["version"]: |
1004 show_version(u) | 1012 show_version(get_ui()) |
1005 sys.exit(0) | 1013 sys.exit(0) |
1006 | 1014 |
1007 try: | 1015 try: |
1008 i = find(cmd) | 1016 i = find(cmd) |
1009 except UnknownCommand: | 1017 except UnknownCommand: |
1018 u = get_ui() | |
1010 u.warn("hg: unknown command '%s'\n" % cmd) | 1019 u.warn("hg: unknown command '%s'\n" % cmd) |
1011 help(u) | 1020 help(u) |
1012 sys.exit(1) | 1021 sys.exit(1) |
1013 | 1022 |
1014 signal.signal(signal.SIGTERM, catchterm) | 1023 # combine global options into local |
1024 c = list(i[1]) | |
1025 l = len(c) | |
1026 for o in opts: | |
1027 c.append((o[0], o[1], options[o[1]], o[3])) | |
1015 | 1028 |
1016 cmdoptions = {} | 1029 cmdoptions = {} |
1017 try: | 1030 try: |
1018 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | 1031 args = fancyopts.fancyopts(args, c, cmdoptions, i[2]) |
1019 except fancyopts.getopt.GetoptError, inst: | 1032 except fancyopts.getopt.GetoptError, inst: |
1033 u = get_ui() | |
1020 u.warn("hg %s: %s\n" % (cmd, inst)) | 1034 u.warn("hg %s: %s\n" % (cmd, inst)) |
1021 help(u, cmd) | 1035 help(u, cmd) |
1022 sys.exit(-1) | 1036 sys.exit(-1) |
1037 | |
1038 # separate global options back out | |
1039 for o in opts: | |
1040 n = o[1] | |
1041 options[n] = cmdoptions[n] | |
1042 del cmdoptions[n] | |
1043 | |
1044 u = get_ui() | |
1023 | 1045 |
1024 try: | 1046 try: |
1025 try: | 1047 try: |
1026 if cmd not in norepo.split(): | 1048 if cmd not in norepo.split(): |
1027 path = options["repository"] or "" | 1049 path = options["repository"] or "" |