Skip to content

Commit

Permalink
Where there is no suggestions on spell checker print nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
benoittgt committed Aug 14, 2024
1 parent cbe7d5f commit a45ecb5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/dry/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def error(result)

# @since 1.1.1
def spell_checker(result, arguments)
err.puts SpellChecker.call(result, arguments)
spell_checker = SpellChecker.call(result, arguments)
err.puts spell_checker if spell_checker
puts
err.puts Usage.call(result)
exit(1)
Expand Down
13 changes: 9 additions & 4 deletions lib/dry/cli/spell_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ def self.call(result, arguments)
output = []

suggestions = DidYouMean::SpellChecker.new(dictionary: commands).correct(cmd.first)
output << "I don't know how to '#{cmd.join(' ')}'."
output << " Did you mean: '#{suggestions.first}' ?" if suggestions.any?

output.join("")
if suggestions.any?
"I don't know how to '#{cmd.join(' ')}'. Did you mean: '#{suggestions.first}' ?"
end
end

# @since 1.1.1
# @api private
def self.cmd_to_spell(arguments, result_names)
arguments - result_names
end

# @since 1.1.1
# @api private
def self.ignore?(cmd)
cmd.empty? || cmd.first.start_with?("-")
end
end
end
end
1 change: 1 addition & 0 deletions spec/integration/inherited_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
based logs APP # Display recent log output
based run APP CMD # Run a one-off process inside your app
based subrun APP CMD
OUT
expect(output).to eq(expected)
end
Expand Down
1 change: 0 additions & 1 deletion spec/integration/rendering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
_, stderr, = Open3.capture3("foo unknown")

expected = <<~DESC
I don't know how to 'unknown'.
Commands:
foo assets [SUBCOMMAND]
foo callbacks DIR # Command with callbacks
Expand Down

0 comments on commit a45ecb5

Please sign in to comment.