dry-cli icon indicating copy to clipboard operation
dry-cli copied to clipboard

Provide help when there is a typo in a command

Open benoittgt opened this issue 6 months ago • 0 comments

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 avatar Aug 14 '24 09:08 benoittgt