Module: Jura::CommandHandler

Defined in:
lib/jura/command_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(cmd_buffer) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jura/command_handler.rb', line 11

def self.call(cmd_buffer)
  cmd_name, sub_cmd, *args = cmd_buffer.to_s.strip.split(" ")

  if cmd_name.nil? || cmd_name.empty?
    # TODO: return and execute empty command error
  end

  unless Jura::RootControl.instance.support_command?(cmd_name)
    return Command::Invalid.execute("Command not found: #{cmd_name}. Run #{"help".inspect} for more informations")
  end

  puts '' # Empty line
  Jura::RootControl.instance.execute_command(cmd_name, sub_cmd: sub_cmd, args: args)
  puts '' # Empty line
rescue Command::Board::RequiredBoardIdError => _
  puts 'Please select a board first!'
  Jura::RootControl.execute_command('select')
end

Instance Method Details

#generate_suggestions(buffer, command_buffer) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/jura/command_handler.rb', line 30

def generate_suggestions(buffer, command_buffer)
  commands = {
    "board" => %[list select],
    "issue" => %[list],
    "sprint" => %[list show]
  }

  commands.keys.grep(/^#{Regexp.escape(buffer)}/)
end