Parent

Cri::Command

Cri::Command represents a command that can be executed on the commandline. It is an abstract superclass for all commands.

Attributes

base[RW]

Public Instance Methods

<=>(other) click to toggle source

Compares this command’s name to the other given command’s name.

# File lib/cri/command.rb, line 99
def <=>(other)
  self.name <=> other.name
end
aliases() click to toggle source

Returns an array of strings containing the aliases for this command. Subclasses must implement this method.

# File lib/cri/command.rb, line 17
def aliases
  raise NotImplementedError.new("Command subclasses should override #aliases")
end
help() click to toggle source

Returns the help text for this command.

# File lib/cri/command.rb, line 63
def help
  text = ''

  # Append usage
  text << usage + "\n"

  # Append aliases
  unless aliases.empty?
    text << "\n"
    text << "aliases: #{aliases.join(' ')}\n"
  end

  # Append short description
  text << "\n"
  text << short_desc + "\n"

  # Append long description
  text << "\n"
  text << long_desc.wrap_and_indent(78, 4) + "\n"

  # Append options
  all_option_definitions = base.global_option_definitions + option_definitions
  unless all_option_definitions.empty?
    text << "\n"
    text << "options:\n"
    text << "\n"
    all_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
      text << sprintf("    -%1s --%-10s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
    end
  end

  # Return text
  text
end
long_desc() click to toggle source

Returns a string containing this command’s complete description, which should explain what this command does and how it works in detail. Subclasses must implement this method.

# File lib/cri/command.rb, line 31
def long_desc
  raise NotImplementedError.new("Command subclasses should override #long_desc")
end
name() click to toggle source

Returns a string containing the name of thi command. Subclasses must implement this method.

# File lib/cri/command.rb, line 11
def name
  raise NotImplementedError.new("Command subclasses should override #name")
end
option_definitions() click to toggle source

Returns an array containing this command’s option definitions. See the documentation for Cri::OptionParser for details on what option definitions look like. Subclasses may implement this method if the command has options.

# File lib/cri/command.rb, line 45
def option_definitions
  []
end
run(options, arguments) click to toggle source

Executes the command. Subclasses must implement this method (obviously… what’s the point of a command that can’t be run?).

options

A hash containing the parsed commandline options. For example, ‘–foo=bar’ will be converted into { :foo => ‘bar’ }. See the Cri::OptionParser documentation for details.

arguments

An array of strings representing the commandline arguments given to this command.

# File lib/cri/command.rb, line 58
def run(options, arguments)
  raise NotImplementedError.new("Command subclasses should override #run")
end
short_desc() click to toggle source

Returns a string containing this command’s short description, which should not be longer than 50 characters. Subclasses must implement this method.

# File lib/cri/command.rb, line 24
def short_desc
  raise NotImplementedError.new("Command subclasses should override #short_desc")
end
usage() click to toggle source

Returns a string containing this command’s usage. Subclasses must implement this method.

# File lib/cri/command.rb, line 37
def usage
  raise NotImplementedError.new("Command subclasses should override #usage")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.