title: Is there a way to easily do word suggestions in a CLI?
body: <p>I am wondering if there is a package available to help create something similar to what git has built in when you misspell a command, and it suggests existing commands. I am currently writing a CLI, and one of the features of the CLI is dynamically defining commands to dispatch <a href="https://github.com/Descent098/ahd" rel="nofollow noreferrer">here is the link for context</a>, so misspellings are quite common.</p>
  <p>Ideally I am looking for a way to pass a word, with a list of target words and get suggestions based on how close the input word is to one of the target words.</p>
  <p>So for example:</p>
  <pre class="lang-py prettyprint-override"><code>def suggest(input_word:str, valid_words:list) -&gt; str:
    suggestion = &quot;&quot; # The word in list valid_words that input_word is closest to 
    ... # Do stuff
    return suggestion
  </code></pre>
  <p>Which can be used like so:</p>
  <pre class="lang-py prettyprint-override"><code>suggest(&quot;biild&quot;, [&quot;build&quot;, &quot;init&quot;, &quot;preview&quot;]) # Returns &quot;build&quot;
  </code></pre>
  <p>Then with the cli I can use the function to print a message if a command does not exist and is likely misspelled like:</p>
  <pre class="lang-sh prettyprint-override"><code>$ ahd biild
  Command &quot;biild&quot; does not exist, did you mean:
      
      ahd build
  </code></pre>
  <p>I am not even looking for a full implementation, even just a suggestion on libraries that could help to do the string similarity check would be appreciated. Everything I have found so far is only a CLI with no API to hook into.</p>