class Nehm::Command

Base class for all Nehm commands. When creating a new nehm command, define initialize, execute, arguments, program_name, summary and usage (as appropriate) See the above mentioned methods for details

Attributes

options[RW]

Hash with options of the command

options_descs[RW]

Hash with descriptions of each option

Public Class Methods

new() click to toggle source

In ‘initialize’ should be defined all options by method ‘add_option’ See get_command.rb as example

# File lib/nehm/command.rb, line 27
def initialize
  @options = {}
  @options_descs = {}
end

Public Instance Methods

add_option(option, usage, desc) click to toggle source

Add a command-line option

Nehm don’t use options with dashes to be more user-friendly

See ‘get_command.rb’ as example

# File lib/nehm/command.rb, line 103
def add_option(option, usage, desc)
  @options[option] = nil
  @options_descs[usage] = desc
end
arguments() click to toggle source

Override to provide details of the arguments a command takes

For example:

def usage
  "#{program_name} COMMAND"
end

def arguments
  ['COMMAND', 'name of command to show help']
end
# File lib/nehm/command.rb, line 72
def arguments
  {}
end
execute() click to toggle source

Override to provide command handling

options will be filled in with your parsed options, unparsed options will be left in options[:args]

# File lib/nehm/command.rb, line 55
def execute
  raise StandardError, 'generic command has no actions'
end
handle_options(args) click to toggle source

Handle the given list of arguments by parsing them and recording the results

# File lib/nehm/command.rb, line 44
def handle_options(args)
  parser = OptionParser.new(args, self)
  parser.parse
end
invoke(args) click to toggle source

Invoke the command with the given list of arguments

# File lib/nehm/command.rb, line 35
def invoke(args)
  handle_options(args)
  execute
end
program_name() click to toggle source

The name of the command for command-line invocation

# File lib/nehm/command.rb, line 79
def program_name
end
summary() click to toggle source

Override to display a short description of what this command does

# File lib/nehm/command.rb, line 85
def summary
end
usage() click to toggle source

Override to display the usage for an individual nehm command

The text “[options]” is automatically appended to the usage text

# File lib/nehm/command.rb, line 93
def usage
end