comparison mercurial/cmdutil.py @ 24222:02d7b5cd373b

dispatch: offer suggestions of similar-named commands When suggestions are available, we show those suggestions instead of showing some help output.
author Augie Fackler <augie@google.com>
date Tue, 10 Feb 2015 15:59:12 -0500
parents 4bb348ae43cb
children 5ac8ce04baa2
comparison
equal deleted inserted replaced
24221:4e240d6ab898 24222:02d7b5cd373b
32 # short-circuit exact matches, "log" alias beats "^log|history" 32 # short-circuit exact matches, "log" alias beats "^log|history"
33 keys = [cmd] 33 keys = [cmd]
34 else: 34 else:
35 keys = table.keys() 35 keys = table.keys()
36 36
37 allcmds = []
37 for e in keys: 38 for e in keys:
38 aliases = parsealiases(e) 39 aliases = parsealiases(e)
40 allcmds.extend(aliases)
39 found = None 41 found = None
40 if cmd in aliases: 42 if cmd in aliases:
41 found = cmd 43 found = cmd
42 elif not strict: 44 elif not strict:
43 for a in aliases: 45 for a in aliases:
51 choice[found] = (aliases, table[e]) 53 choice[found] = (aliases, table[e])
52 54
53 if not choice and debugchoice: 55 if not choice and debugchoice:
54 choice = debugchoice 56 choice = debugchoice
55 57
56 return choice 58 return choice, allcmds
57 59
58 def findcmd(cmd, table, strict=True): 60 def findcmd(cmd, table, strict=True):
59 """Return (aliases, command table entry) for command string.""" 61 """Return (aliases, command table entry) for command string."""
60 choice = findpossible(cmd, table, strict) 62 choice, allcmds = findpossible(cmd, table, strict)
61 63
62 if cmd in choice: 64 if cmd in choice:
63 return choice[cmd] 65 return choice[cmd]
64 66
65 if len(choice) > 1: 67 if len(choice) > 1:
68 raise error.AmbiguousCommand(cmd, clist) 70 raise error.AmbiguousCommand(cmd, clist)
69 71
70 if choice: 72 if choice:
71 return choice.values()[0] 73 return choice.values()[0]
72 74
73 raise error.UnknownCommand(cmd) 75 raise error.UnknownCommand(cmd, allcmds)
74 76
75 def findrepo(p): 77 def findrepo(p):
76 while not os.path.isdir(os.path.join(p, ".hg")): 78 while not os.path.isdir(os.path.join(p, ".hg")):
77 oldp, p = p, os.path.dirname(p) 79 oldp, p = p, os.path.dirname(p)
78 if p == oldp: 80 if p == oldp: