Sha256: 6b8a8ead1f1039093218f37b2e6111c4c86c64119624a99537b4833eb4edac1e

Contents?: true

Size: 873 Bytes

Versions: 5

Compression:

Stored size: 873 Bytes

Contents

module Mercenary
  class Program < Command
    attr_reader :optparse
    attr_reader :config

    # Public: Creates a new Program
    #
    # name - the name of the program
    #
    # Returns nothing
    def initialize(name)
      @config = {}
      super(name)
    end

    # Public: Run the program
    #
    # argv - an array of string args (usually ARGV)
    #
    # Returns nothing
    def go(argv)
      logger.debug("Using args passed in: #{argv.inspect}")

      cmd = nil

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

      @optparse.parse!(argv)

      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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mercenary-0.3.4 lib/mercenary/program.rb
mercenary-0.3.3 lib/mercenary/program.rb
mercenary-0.3.2 lib/mercenary/program.rb
mercenary-0.3.1 lib/mercenary/program.rb
mercenary-0.3.0 lib/mercenary/program.rb