Class: Ego::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ego/runner.rb

Overview

The Runner class, given an array of arguments, initializes the required objects and executes the request.

Constant Summary collapse

PROMPT =

Prompt to display in shell-mode

'ego, '.green.freeze
QUIT =

Pattern that triggers shell-mode to exit

/^q(uit)?|exit|(good)?bye$/

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Takes an array of arguments and parses them into options:

Examples:

runner = Ego::Runner.new(ARGV)

Parameters:

  • argv (Array)

    command-line arguments



22
23
24
# File 'lib/ego/runner.rb', line 22

def initialize(argv)
  @options = Options.new(argv)
end

Instance Method Details

#runvoid

This method returns an undefined value.

Run the appropriate action based on the arguments provided to #initialize.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ego/runner.rb', line 30

def run
  case @options.mode
  when :help
    Printer.errs @options.usage_error, "\n" if @options.usage_error

    Printer.puts @options.usage

    exit(-1) if @options.usage_error
  when :version
    Printer.puts "ego v#{Ego::VERSION}"
  when :template
    helper = PluginHelper.new(
      query: (@options.query unless @options.query.empty?),
      program_name: @options.usage.program_name
    )
    Printer.puts helper.template
  when :shell
    start_shell(robot_factory)
  else
    handle_query(robot_factory, @options.query)
  end
rescue RobotError => e
  Printer.errs e.message
  exit(-2)
end