Show More
@@ -7,6 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re |
|
10 | import difflib | |
|
10 | 11 | import util, commands, hg, fancyopts, extensions, hook, error |
|
11 | 12 | import cmdutil, encoding |
|
12 | 13 | import ui as uimod |
@@ -27,7 +28,17 b' def run():' | |||
|
27 | 28 | "run the command in sys.argv" |
|
28 | 29 | sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255) |
|
29 | 30 | |
|
31 | def _getsimilar(symbols, value): | |
|
32 | sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | |
|
33 | # The cutoff for similarity here is pretty arbitrary. It should | |
|
34 | # probably be investigated and tweaked. | |
|
35 | return [s for s in symbols if sim(s) > 0.6] | |
|
36 | ||
|
30 | 37 | def _formatparse(write, inst): |
|
38 | similar = [] | |
|
39 | if isinstance(inst, error.UnknownIdentifier): | |
|
40 | # make sure to check fileset first, as revset can invoke fileset | |
|
41 | similar = _getsimilar(inst.symbols, inst.function) | |
|
31 | 42 | if len(inst.args) > 1: |
|
32 | 43 | write(_("hg: parse error at %s: %s\n") % |
|
33 | 44 | (inst.args[1], inst.args[0])) |
@@ -35,6 +46,12 b' def _formatparse(write, inst):' | |||
|
35 | 46 | write(_("unexpected leading whitespace\n")) |
|
36 | 47 | else: |
|
37 | 48 | write(_("hg: parse error: %s\n") % inst.args[0]) |
|
49 | if similar: | |
|
50 | if len(similar) == 1: | |
|
51 | write(_("(did you mean %r?)\n") % similar[0]) | |
|
52 | else: | |
|
53 | ss = ", ".join(sorted(similar)) | |
|
54 | write(_("(did you mean one of %s?)\n") % ss) | |
|
38 | 55 | |
|
39 | 56 | def dispatch(req): |
|
40 | 57 | "run the command specified in req.args" |
@@ -891,12 +891,15 b' parentrevspec' | |||
|
891 | 891 | Bogus function gets suggestions |
|
892 | 892 | $ log 'add()' |
|
893 | 893 | hg: parse error: not a function: add |
|
894 | (did you mean 'adds'?) | |
|
894 | 895 | [255] |
|
895 | 896 | $ log 'added()' |
|
896 | 897 | hg: parse error: not a function: added |
|
898 | (did you mean 'adds'?) | |
|
897 | 899 | [255] |
|
898 | 900 | $ log 'remo()' |
|
899 | 901 | hg: parse error: not a function: remo |
|
902 | (did you mean one of remote, removes?) | |
|
900 | 903 | [255] |
|
901 | 904 | $ log 'babar()' |
|
902 | 905 | hg: parse error: not a function: babar |
General Comments 0
You need to be logged in to leave comments.
Login now