equal
deleted
inserted
replaced
13 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") |
13 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") |
14 demandload(globals(), "errno socket version struct atexit sets bz2") |
14 demandload(globals(), "errno socket version struct atexit sets bz2") |
15 |
15 |
16 class UnknownCommand(Exception): |
16 class UnknownCommand(Exception): |
17 """Exception raised if command is not in the command table.""" |
17 """Exception raised if command is not in the command table.""" |
|
18 class AmbiguousCommand(Exception): |
|
19 """Exception raised if command shortcut matches more than one command.""" |
18 |
20 |
19 def filterfiles(filters, files): |
21 def filterfiles(filters, files): |
20 l = [x for x in files if x in filters] |
22 l = [x for x in files if x in filters] |
21 |
23 |
22 for t in filters: |
24 for t in filters: |
385 option_lists = [] |
387 option_lists = [] |
386 if cmd and cmd != 'shortlist': |
388 if cmd and cmd != 'shortlist': |
387 if with_version: |
389 if with_version: |
388 show_version(ui) |
390 show_version(ui) |
389 ui.write('\n') |
391 ui.write('\n') |
390 key, i = find(cmd) |
392 aliases, i = find(cmd) |
391 # synopsis |
393 # synopsis |
392 ui.write("%s\n\n" % i[2]) |
394 ui.write("%s\n\n" % i[2]) |
393 |
395 |
394 # description |
396 # description |
395 doc = i[0].__doc__ |
397 doc = i[0].__doc__ |
397 doc = doc.splitlines(0)[0] |
399 doc = doc.splitlines(0)[0] |
398 ui.write("%s\n" % doc.rstrip()) |
400 ui.write("%s\n" % doc.rstrip()) |
399 |
401 |
400 if not ui.quiet: |
402 if not ui.quiet: |
401 # aliases |
403 # aliases |
402 aliases = ', '.join(key.split('|')[1:]) |
404 if len(aliases) > 1: |
403 if aliases: |
405 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
404 ui.write(_("\naliases: %s\n") % aliases) |
|
405 |
406 |
406 # options |
407 # options |
407 if i[1]: |
408 if i[1]: |
408 option_lists.append(("options", i[1])) |
409 option_lists.append(("options", i[1])) |
409 |
410 |
2373 |
2374 |
2374 norepo = ("clone init version help debugancestor debugconfig debugdata" |
2375 norepo = ("clone init version help debugancestor debugconfig debugdata" |
2375 " debugindex debugindexdot paths") |
2376 " debugindex debugindexdot paths") |
2376 |
2377 |
2377 def find(cmd): |
2378 def find(cmd): |
2378 choice = [] |
2379 """Return (aliases, command table entry) for command string.""" |
|
2380 choice = None |
2379 for e in table.keys(): |
2381 for e in table.keys(): |
2380 aliases = e.lstrip("^").split("|") |
2382 aliases = e.lstrip("^").split("|") |
2381 if cmd in aliases: |
2383 if cmd in aliases: |
2382 return e, table[e] |
2384 return aliases, table[e] |
2383 for a in aliases: |
2385 for a in aliases: |
2384 if a.startswith(cmd): |
2386 if a.startswith(cmd): |
2385 choice.append(e) |
2387 if choice: |
2386 if len(choice) == 1: |
2388 raise AmbiguousCommand(cmd) |
2387 e = choice[0] |
2389 else: |
2388 return e, table[e] |
2390 choice = aliases, table[e] |
|
2391 if choice: |
|
2392 return choice |
2389 |
2393 |
2390 raise UnknownCommand(cmd) |
2394 raise UnknownCommand(cmd) |
2391 |
2395 |
2392 class SignalInterrupt(Exception): |
2396 class SignalInterrupt(Exception): |
2393 """Exception raised on SIGTERM and SIGHUP.""" |
2397 """Exception raised on SIGTERM and SIGHUP.""" |
2421 except fancyopts.getopt.GetoptError, inst: |
2425 except fancyopts.getopt.GetoptError, inst: |
2422 raise ParseError(None, inst) |
2426 raise ParseError(None, inst) |
2423 |
2427 |
2424 cmd, args = args[0], args[1:] |
2428 cmd, args = args[0], args[1:] |
2425 |
2429 |
2426 i = find(cmd)[1] |
2430 aliases, i = find(cmd) |
|
2431 cmd = aliases[0] |
2427 c = list(i[1]) |
2432 c = list(i[1]) |
2428 else: |
2433 else: |
2429 cmd = None |
2434 cmd = None |
2430 c = [] |
2435 c = [] |
2431 |
2436 |
2501 help_(u, inst.args[0]) |
2506 help_(u, inst.args[0]) |
2502 else: |
2507 else: |
2503 u.warn(_("hg: %s\n") % inst.args[1]) |
2508 u.warn(_("hg: %s\n") % inst.args[1]) |
2504 help_(u, 'shortlist') |
2509 help_(u, 'shortlist') |
2505 sys.exit(-1) |
2510 sys.exit(-1) |
|
2511 except AmbiguousCommand, inst: |
|
2512 u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0]) |
|
2513 sys.exit(1) |
2506 except UnknownCommand, inst: |
2514 except UnknownCommand, inst: |
2507 u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
2515 u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
2508 help_(u, 'shortlist') |
2516 help_(u, 'shortlist') |
2509 sys.exit(1) |
2517 sys.exit(1) |
2510 |
2518 |