-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest most simillar command #1272
Conversation
cmd2/cmd2.py
Outdated
@@ -529,6 +531,9 @@ def __init__( | |||
# Add functions decorated to be subcommands | |||
self._register_subcommands(self) | |||
|
|||
self.suggest_similar_command = suggest_similar_command | |||
self.default_suggestion_message = "The most similar command is {}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I doubt I tend to fall back on what bash does. How about:
', did you mean: {}'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my first choice. I changed it because of git:
git comit
git: 'comit' is not a git command. See 'git --help'.
The most similar command is
commit
But sure, I can change it.
cmd2/cmd2.py
Outdated
if self.suggest_similar_command: | ||
suggested_command = self._suggest_similar_command(statement.command) | ||
if suggested_command: | ||
err_msg = err_msg + os.linesep + self.default_suggestion_message.format(suggested_command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my alternate suggestion message, no need for line separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use a space
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1272 +/- ##
=======================================
Coverage 98.54% 98.55%
=======================================
Files 22 22
Lines 5705 5728 +23
=======================================
+ Hits 5622 5645 +23
Misses 83 83
☔ View full report in Codecov by Sentry. |
I see doc jobs are failing but I don't think that's related to this branch |
It would be great to have this merged |
My PR just merged which also addresses many of the issues you probably ran into. You may want to rebase over latest to see. |
I'm not sure what's going on with your branch but my changes are now showing up as changes in your branch. I highly suggest squashing related commits and then rebasing it all on top of latest master. |
b38757c
to
f0b0580
Compare
I think it's done now. I made a mistake rebasing, I'm much more used to mercurial to be honest. |
@anselor I applied the changes from the formatter jobs and the doc job. Don't know about the linter. It looks like it is not from my PR |
There pyinvoke commands you can run locally to check |
I'm trying
They passed now (Though with python 3.8 in my local setup). |
@federicoemartinez The linter problem looks spurious and not applicable to the situation. Would you mind just adding |
done! |
As far as I'm aware it passed before the last PR. What I've sometimes see happen is the validation library updates and new errors are found that did not previously fail. |
closes #1271
The app can be configured to suggest the most similar command. In that case, the most similar command of the visible commands (more similar than a threshold) will be suggested and added to the default error message.
By default SequenceMatcher.ratio() from the standard library is used but a subclass can define _suggest_similar_command with a new algorithm.