Class: CommandRunner::CommandInstance
- Inherits:
-
Object
- Object
- CommandRunner::CommandInstance
- Defined in:
- lib/command_runner.rb
Instance Method Summary collapse
-
#initialize(default_args, default_timeout, default_environment, allowed_sub_commands, debug_log, split_stderr, encoding, options) ⇒ CommandInstance
constructor
A new instance of CommandInstance.
- #run(*args, timeout: nil, environment: {}) ⇒ Object
Constructor Details
#initialize(default_args, default_timeout, default_environment, allowed_sub_commands, debug_log, split_stderr, encoding, options) ⇒ CommandInstance
Returns a new instance of CommandInstance.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/command_runner.rb', line 236 def initialize(default_args, default_timeout, default_environment, allowed_sub_commands, debug_log, split_stderr, encoding, ) 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 = end |
Instance Method Details
#run(*args, timeout: nil, environment: {}) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# 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: ) end |