changeset 7636 | e3f8c6d6b72e |
parent 7633 | 08cabecfa8a8 |
child 7637 | 1d54e2f6c0b7 |
7635:d22c43724745 | 7636:e3f8c6d6b72e |
---|---|
9 from repo import RepoError |
9 from repo import RepoError |
10 import os, sys, atexit, signal, pdb, socket, errno, shlex, time |
10 import os, sys, atexit, signal, pdb, socket, errno, shlex, time |
11 import util, commands, hg, lock, fancyopts, extensions, hook, error |
11 import util, commands, hg, lock, fancyopts, extensions, hook, error |
12 import cmdutil |
12 import cmdutil |
13 import ui as _ui |
13 import ui as _ui |
14 |
|
15 class ParseError(Exception): |
|
16 """Exception raised on errors in parsing the command line.""" |
|
17 |
14 |
18 def run(): |
15 def run(): |
19 "run the command in sys.argv" |
16 "run the command in sys.argv" |
20 sys.exit(dispatch(sys.argv[1:])) |
17 sys.exit(dispatch(sys.argv[1:])) |
21 |
18 |
50 if '--debugger' in args: |
47 if '--debugger' in args: |
51 pdb.post_mortem(sys.exc_info()[2]) |
48 pdb.post_mortem(sys.exc_info()[2]) |
52 ui.print_exc() |
49 ui.print_exc() |
53 raise |
50 raise |
54 |
51 |
55 except ParseError, inst: |
52 except error.ParseError, inst: |
56 if inst.args[0]: |
53 if inst.args[0]: |
57 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
54 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
58 commands.help_(ui, inst.args[0]) |
55 commands.help_(ui, inst.args[0]) |
59 else: |
56 else: |
60 ui.warn(_("hg: %s\n") % inst.args[1]) |
57 ui.warn(_("hg: %s\n") % inst.args[1]) |
165 cmdoptions = {} |
162 cmdoptions = {} |
166 |
163 |
167 try: |
164 try: |
168 args = fancyopts.fancyopts(args, commands.globalopts, options) |
165 args = fancyopts.fancyopts(args, commands.globalopts, options) |
169 except fancyopts.getopt.GetoptError, inst: |
166 except fancyopts.getopt.GetoptError, inst: |
170 raise ParseError(None, inst) |
167 raise error.ParseError(None, inst) |
171 |
168 |
172 if args: |
169 if args: |
173 cmd, args = args[0], args[1:] |
170 cmd, args = args[0], args[1:] |
174 aliases, i = cmdutil.findcmd(cmd, commands.table, |
171 aliases, i = cmdutil.findcmd(cmd, commands.table, |
175 ui.config("ui", "strict")) |
172 ui.config("ui", "strict")) |
187 c.append((o[0], o[1], options[o[1]], o[3])) |
184 c.append((o[0], o[1], options[o[1]], o[3])) |
188 |
185 |
189 try: |
186 try: |
190 args = fancyopts.fancyopts(args, c, cmdoptions) |
187 args = fancyopts.fancyopts(args, c, cmdoptions) |
191 except fancyopts.getopt.GetoptError, inst: |
188 except fancyopts.getopt.GetoptError, inst: |
192 raise ParseError(cmd, inst) |
189 raise error.ParseError(cmd, inst) |
193 |
190 |
194 # separate global options back out |
191 # separate global options back out |
195 for o in commands.globalopts: |
192 for o in commands.globalopts: |
196 n = o[1] |
193 n = o[1] |
197 options[n] = cmdoptions[n] |
194 options[n] = cmdoptions[n] |
373 def _runcommand(ui, options, cmd, cmdfunc): |
370 def _runcommand(ui, options, cmd, cmdfunc): |
374 def checkargs(): |
371 def checkargs(): |
375 try: |
372 try: |
376 return cmdfunc() |
373 return cmdfunc() |
377 except util.SignatureError: |
374 except util.SignatureError: |
378 raise ParseError(cmd, _("invalid arguments")) |
375 raise error.ParseError(cmd, _("invalid arguments")) |
379 |
376 |
380 if options['profile']: |
377 if options['profile']: |
381 import hotshot, hotshot.stats |
378 import hotshot, hotshot.stats |
382 prof = hotshot.Profile("hg.prof") |
379 prof = hotshot.Profile("hg.prof") |
383 try: |
380 try: |