Class: Mercenary::Program

### Home Classes Methods

### In Files

- lib/mercenary/program.rb

### Parent

Mercenary::Command

### Methods

- ::new
- #go

### Class/Module Index

Quicksearch

- Mercenary
- Mercenary::Command
- Mercenary::Option
- Mercenary::Presenter
- Mercenary::Program

No matching classes.

# Mercenary::Program

### Attributes

config[R]
optparse[R]

### Public Class Methods

new(name) click to toggle source

Public: Creates a new Program

name - the name of the program

Returns nothing

    # File lib/mercenary/program.rb, line 11
    def initialize(name)
      @config = {}
      super(name)
    end

### Public Instance Methods

go(argv) click to toggle source

Public: Run the program

argv - an array of string args (usually ARGV)

Returns nothing

    # File lib/mercenary/program.rb, line 21
    def go(argv)
      logger.debug("Using args passed in: #{argv.inspect}")

      cmd = nil

      @optparse = OptionParser.new do |opts|
        cmd = super(argv, opts, @config)
      end

      begin
        @optparse.parse!(argv)
      rescue OptionParser::InvalidOption => e
        logger.error "Whoops, we can't understand your command."
        logger.error "#{e.message}"
        logger.error "Run your command again with the --help switch to see available options."
        abort
      end

      logger.debug("Parsed config: #{@config.inspect}")

      begin
        cmd.execute(argv, @config)
      rescue => e
        if cmd.trace
          raise e
        else
          logger.error e.message
          abort
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.