Module: WifiWand::Commands::Registry

Included in:
WifiWand::CommandLineInterface, WifiWand::CommandLineParser
Defined in:
lib/wifi_wand/commands/registry.rb

Instance Method Summary collapse

Instance Method Details

#attempt_command_action(command_string, &error_handler_block) ⇒ Object

Look up the command name and, if found, run it. If not, execute the passed block.



78
79
80
81
82
83
84
85
86
87
# File 'lib/wifi_wand/commands/registry.rb', line 78

def attempt_command_action(command_string, *, &error_handler_block)
  action = find_command_action(command_string)

  if action
    action.call(*)
  else
    error_handler_block.call
    nil
  end
end

#find_command(command_string) ⇒ Object



63
64
65
# File 'lib/wifi_wand/commands/registry.rb', line 63

def find_command(command_string)
  commands.detect { |command| command.aliases.include?(command_string) }
end

#find_command_action(command_string) ⇒ Object



72
73
74
75
# File 'lib/wifi_wand/commands/registry.rb', line 72

def find_command_action(command_string)
  command = resolve_command(command_string)
  command&.method(:call)
end

#resolve_command(command_string) ⇒ Object



67
68
69
70
# File 'lib/wifi_wand/commands/registry.rb', line 67

def resolve_command(command_string)
  command = find_command(command_string)
  command&.bind(self)
end