Class: R2do::Commands::HelpCommand

Inherits:
R2do::Command show all
Defined in:
lib/r2do/commands/help_command.rb

Instance Attribute Summary

Attributes inherited from R2do::Command

#description, #extended, #short

Instance Method Summary collapse

Methods inherited from R2do::Command

#help, #to_s

Constructor Details

#initialize(cmd_list) ⇒ HelpCommand

Returns a new instance of HelpCommand.



21
22
23
24
25
# File 'lib/r2do/commands/help_command.rb', line 21

def initialize(cmd_list)
  super('h', 'help', 'Shows the help for a given command')

  @cmd_list = cmd_list
end

Instance Method Details

#execute(args) ⇒ void

This method returns an undefined value.

Initializes the applications and resets the datafile

Parameters:

  • args (Array)

    the arguments passed to the app by the user



31
32
33
34
35
36
37
38
39
40
# File 'lib/r2do/commands/help_command.rb', line 31

def execute(args)
  argument = args[1]

  cmd = @cmd_list.find { |c| c.short == argument or c.extended == argument }
  if cmd.nil?
    raise InvalidCommandError, "Invalid command. See 'r2do -h'"
  end

  UI.status(cmd.help())
end