Class: Ergane::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, argv) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
# File 'lib/ergane/runner.rb', line 7

def initialize(root, argv)
  @root = root
  @argv = argv.dup
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



5
6
7
# File 'lib/ergane/runner.rb', line 5

def argv
  @argv
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/ergane/runner.rb', line 5

def root
  @root
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ergane/runner.rb', line 12

def execute
  command_class, remaining, path = resolve(root, argv)

  if help_requested?(remaining)
    $stdout.puts HelpFormatter.new(command_class, command_path: path).format
    return
  end

  if version_requested?(remaining) && command_class.respond_to?(:version) && command_class.version
    $stdout.puts "#{command_class.command_name} #{command_class.version}"
    return
  end

  instance = command_class.new(remaining)
  instance.run(*instance.args)
end