Class: R2do::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/r2do/commands/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(short, extended, description) ⇒ Command

Creates an instance of a Command

Parameters:

  • short (String)

    the short option name for this command

  • extended (String)

    the full option name for this command

  • argument (String)

    the optional argument for commands that have arguments

  • description (String)

    the command’s description



33
34
35
36
37
38
39
40
41
# File 'lib/r2do/commands/command.rb', line 33

def initialize(short, extended, description)
  if short.nil? or extended.nil? or description.nil?
    raise ArgumentError
  end

  @short = short
  @extended = extended
  @description = description
end

Instance Attribute Details

#descriptionString (readonly)

Returns the description for the command.

Returns:

  • (String)

    the description for the command.



25
26
27
# File 'lib/r2do/commands/command.rb', line 25

def description
  @description
end

#extendedString (readonly)

Returns the name of this command.

Returns:

  • (String)

    the name of this command.



23
24
25
# File 'lib/r2do/commands/command.rb', line 23

def extended
  @extended
end

#shortString (readonly)

Returns the value for the command switch.

Returns:

  • (String)

    the value for the command switch.



21
22
23
# File 'lib/r2do/commands/command.rb', line 21

def short
  @short
end

Instance Method Details

#execute(args) ⇒ void

This method returns an undefined value.

Executes the callback of this command

Parameters:

  • args (Array)

    the collection of arguments

Raises:

  • (ScriptError)


47
48
49
# File 'lib/r2do/commands/command.rb', line 47

def execute(args)
  raise ScriptError, "Cannot call execute on an abstract command"
end

#helpObject



51
52
53
# File 'lib/r2do/commands/command.rb', line 51

def help()
  return "No help available for this command."
end

#to_sString

Returns a string representation of this Command

Returns:

  • (String)

    the representation of this Command



58
59
60
# File 'lib/r2do/commands/command.rb', line 58

def to_s()
  return "%2s, %-10s \t# %s" % [@short, @extended, @description]
end