gbroques / ose-workbench-platform

Common platform for developing Open Source Ecology (OSE) workbenches.
https://ose-workbench-platform.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
6 stars 2 forks source link

Suggest most similar command when incorrect command is typed #50

Open gbroques opened 4 years ago

gbroques commented 4 years ago

For example,

$ osewb lintt
osewb: error: argument command: invalid choice: 'lintt' (choose from 'test', 'lint', 'docs', 'make', 'browse', 'br', 'build', 'bld')

We could say: did you mean osewb lint?.

For example, git does this:

$ git checkoutt
git: 'checkoutt' is not a git command. See 'git --help'.

The most similar command is
        checkout
gbroques commented 4 years ago

The following looks the most promising:

from difflib import SequenceMatcher
m = SequenceMatcher(None, "NEW YORK METS", "NEW YORK MEATS")
m.ratio() ⇒ 0.962962962963