Module: Polytrix::CLI::PerformCommand

Included in:
Polytrix::CLI
Defined in:
lib/polytrix/cli.rb

Overview

Common module to load and invoke a CLI-implementation agnostic command.

Instance Method Summary collapse

Instance Method Details

#perform(task, command, args = nil, additional_options = {}) ⇒ Object

Perform a scenario subcommand.

Parameters:

  • task (String)

    action to take, usually corresponding to the subcommand name

  • command (String)

    command class to create and invoke]

  • args (Array) (defaults to: nil)

    remainder arguments from processed ARGV (default: ‘nil`)

  • additional_options (Hash) (defaults to: {})

    additional configuration needed to set up the command class (default: ‘{}`)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/polytrix/cli.rb', line 20

def perform(task, command, args = nil, additional_options = {})
  require "polytrix/command/#{command}"

  command_options = {
    action: task,
    help: -> { help(task) },
    test_dir: @test_dir,
    shell: shell
  }.merge(additional_options)

  str_const = Thor::Util.camel_case(command)
  klass = ::Polytrix::Command.const_get(str_const)
  klass.new(args, options, command_options).call
end