Sha256: 3e5157c6cc9f440ccab2cbee365945d915a4329b2a9facb59fd835bd8e1f4f05

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require_relative 'version'
require_relative 'options'
require_relative 'filesystem'
require_relative 'robot'
require_relative 'handler'

module Ego
  # The Ego::Runner class, given an array of arguments, initializes the
  # required objects and executes the request.
  class Runner
    # Takes an array of arguments and parses them into options:
    #
    #   runner = Ego::Runner.new(ARGV)
    #
    def initialize(argv)
      @options = Options.new(argv)
      @formatter = Ego::Formatter.new
    end

    # Run the appropriate action based on the arguments provided to
    # #initialize.
    def run
      case @options.mode
      when :help
        if @options.usage_error
          STDERR.puts @options.usage_error, "\n"
        end

        @formatter.puts @options.usage

        exit(-1) if @options.usage_error
      when :version
        @formatter.puts "ego v#{Ego::VERSION}"
      else
        robot = Ego::Robot.new(@options, @formatter)
        Ego::Handler.load Ego::Filesystem.user_handlers
        Ego::Handler.load Ego::Filesystem.builtin_handlers
        Ego::Handler.dispatch robot, @options.query
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ego-0.1.0 lib/ego/runner.rb