Skip to content
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

Provide help when there is a typo in a command #138

Merged
merged 5 commits into from
Sep 21, 2024

Conversation

benoittgt
Copy link
Contributor

Hello

As discussed here https://discourse.dry-rb.org/t/usage-of-did-you-mean-for-command-with-typos-in-dry-cli/1824.

Here is a basic proposal to add spell checker on commands and sub commands using did_you_mean gem.

There is probably a more elegant way to deal with leaf command, but I did a pretty naïve approach.

$ ./foo sub comma
I don't know how to 'comma'. Did you mean: 'command' ?

Commands:
  foo sub command         # Override a subcommand
$ ./foo su
I don't know how to 'su'. Did you mean: 'sub' ?

Commands:
  foo assets [SUBCOMMAND]
  foo callbacks DIR                                          # Command with callbacks
  foo console                                                # Starts Foo console
  foo db [SUBCOMMAND]
  foo destroy [SUBCOMMAND]
  foo exec TASK [DIRS]                                       # Execute a task
  foo generate [SUBCOMMAND]
  foo greeting [RESPONSE]
  foo hello                                                  # Print a greeting
  foo new PROJECT                                            # Generate a new Foo project
  foo root-command [ARGUMENT|SUBCOMMAND]                     # Root command with arguments and subcommands
  foo routes                                                 # Print routes
  foo server                                                 # Start Foo server (only for development)
  foo sub [SUBCOMMAND]
  foo variadic [SUBCOMMAND]
  foo version                                                # Print Foo version

Also to make it work. Locally I add to modify one of the gemfile.

--- a/Gemfile.devtools
+++ b/Gemfile.devtools
@@ -2,8 +2,6 @@
 
 # This file is synced from dry-rb/template-gem repo
 
-gem "rake", ">= 12.3.3"
-
 group :test do
   gem "simplecov", require: false, platforms: :ruby
   gem "simplecov-cobertura", require: false, platforms: :ruby
@@ -13,6 +11,4 @@ group :test do
 end
 
 group :tools do
-  gem "rubocop", "~> 1.55.0"
-  gem "byebug"
 end

Otherwise I had some warnings

A gemspec development dependency (rake, ~> 13.0) is being overridden by a Gemfile dependency (rake, >= 12.3.3).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
A gemspec development dependency (rake, ~> 13.0) is being overridden by a Gemfile dependency (rake, >= 12.3.3).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
A gemspec development dependency (rake, ~> 13.0) is being overridden by a Gemfile dependency (rake, >= 12.3.3).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
A gemspec development dependency (rubocop, ~> 0.82) is being overridden by a Gemfile dependency (rubocop, ~> 1.55.0).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
A gemspec development dependency (rubocop, ~> 0.82) is being overridden by a Gemfile dependency (rubocop, ~> 1.55.0).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
A gemspec development dependency (rubocop, ~> 0.82) is being overridden by a Gemfile dependency (rubocop, ~> 1.55.0).
This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement
Your Gemfile lists the gem byebug (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Your Gemfile lists the gem byebug (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Your Gemfile lists the gem byebug (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.

I didn't look at this in the PR.

@benoittgt benoittgt changed the title Provide help when there is a typo in the command Provide help when there is a typo in a command Aug 14, 2024
@benoittgt benoittgt marked this pull request as ready for review August 14, 2024 09:48
@timriley timriley merged commit 326a5ea into dry-rb:main Sep 21, 2024
6 checks passed
@timriley
Copy link
Member

Thanks @benoittgt!

@benoittgt benoittgt deleted the did_you_mean_failing_command branch September 24, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants