Class: Cliqr::Executor::Runner Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The command runner that handles errors as well

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Runner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new command runner



16
17
18
19
# File 'lib/cliqr/executor/runner.rb', line 16

def initialize(config)
  @config = config
  @validator = Cliqr::ArgumentValidation::Validator.new
end

Instance Method Details

#execute(args, options) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute the command

Parameters:

  • args (Array<String>)

    Arguments that will be used to execute the command

  • options (Hash)

    Options for command execution

Returns:

  • (Integer)

    Exit status of the command execution



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cliqr/executor/runner.rb', line 27

def execute(args, options)
  args = Cliqr::Util.sanitize_args(args, @config)
  action_config, parsed_input = parse(args)
  begin
    command_context = Command::CommandContext.build(action_config, parsed_input, options) \
      do |forwarded_args, forwarded_options|
        execute(forwarded_args, options.merge(forwarded_options))
      end
    Executor::Router.new(action_config).handle(command_context, **options)
  rescue StandardError => e
    raise Cliqr::Error::CommandRuntimeError.new(
      "command '#{action_config.command}' failed", e)
  end
end