Skip to content

Commit

Permalink
CLI update (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
thijssnelleman authored Jan 13, 2025
1 parent bf1c10e commit d1362e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Notable changes to Sparkle will be documented in this file.

### Added
- Flushing completed jobs from jobs command by hitting spacebar [SPRK-313]
- "Did you mean" functionality for typos in CLI commands [SPRK-345]

### Changed
- CI pipeline for unittest now tests for Python 3.10, 3.11 and 3.12
Expand Down
11 changes: 10 additions & 1 deletion sparkle/CLI/_cli_.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ def main() -> None:
print(f"Sparkle autocomplete installed! To enable, run `source {bash_profile}` "
"or restart your terminal.")
else:
print(f"Sparkle does not understand command <{command}>")
print(f"Sparkle does not understand command <{command}>", end="")
from difflib import SequenceMatcher
similarities = [SequenceMatcher(None, command, alt).ratio()
for alt in possible_commands]

if max(similarities) > 0.6:
alternative = possible_commands[similarities.index(max(similarities))]
print(f". Did you mean <{alternative}>?")
else:
print()


if __name__ == "__main__":
Expand Down

0 comments on commit d1362e0

Please sign in to comment.