class CommandRunner::CommandInstance
Public Class Methods
new(default_args, default_timeout, default_environment, allowed_sub_commands, debug_log, split_stderr, encoding, options)
click to toggle source
# File lib/command_runner.rb, line 236 def initialize(default_args, default_timeout, default_environment, allowed_sub_commands, debug_log, split_stderr, encoding, options) unless default_args.first.is_a? Array raise "First argument must be an array of command line args. Found #{default_args}" end @default_args = default_args @default_timeout = default_timeout @default_environment = default_environment @allowed_sub_commands = allowed_sub_commands @debug_log = debug_log @split_stderr = split_stderr @encoding = encoding @options = options end
Public Instance Methods
run(*args, timeout: nil, environment: {})
click to toggle source
# File lib/command_runner.rb, line 251 def run(*args, timeout: nil, environment: {}) args_list = *args if !args_list.nil? && !args_list.empty? && args_list.first.is_a?(Array) if args_list.length > 1 raise "Unsupported args list length: #{args_list.length}" else args_list = args_list.first end end # Check sub command if needed if !args_list.nil? && !args_list.empty? && !@allowed_sub_commands.empty? && !@allowed_sub_commands.include?(args_list.first) raise "Illegal sub command '#{args_list.first}'. Expected #{allowed_sub_commands} (#{allowed_sub_commands.include?(args_list.first)})" end full_args = @default_args.dup full_args[0] += args_list.map {|arg| arg.to_s } CommandRunner.run(*full_args, timeout: (timeout || @default_timeout), environment: @default_environment.merge(environment), debug_log: @debug_log, split_stderr: @split_stderr, encoding: @encoding, options: @options) end