Module: Dry::CLI::SpellChecker Private

Defined in:
lib/dry/cli/spell_checker.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Command(s) usage

Since:

  • 1.1.1

Class Method Summary collapse

Class Method Details

.call(result, arguments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.1



15
16
17
18
19
20
21
22
23
# File 'lib/dry/cli/spell_checker.rb', line 15

def self.call(result, arguments)
  commands = result.children.keys
  cmd = cmd_to_spell(arguments, result.names)

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

.cmd_to_spell(arguments, result_names) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.1



27
28
29
# File 'lib/dry/cli/spell_checker.rb', line 27

def self.cmd_to_spell(arguments, result_names)
  arguments - result_names
end

.ignore?(cmd) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 1.1.1



33
34
35
# File 'lib/dry/cli/spell_checker.rb', line 33

def self.ignore?(cmd)
  cmd.empty? || cmd.first.start_with?("-")
end