Class: Roast::Cogs::Cmd

Inherits:
Roast::Cog show all
Defined in:
lib/roast/cogs/cmd.rb

Defined Under Namespace

Classes: Config, Input, Output

Instance Attribute Summary

Attributes inherited from Roast::Cog

#name, #output

Instance Method Summary collapse

Methods inherited from Roast::Cog

#anonymous?, config_class, #failed?, generate_fallback_name, #initialize, input_class, #run!, #skipped?, #started?, #stopped?, #succeeded?, #type, #wait

Constructor Details

This class inherits a constructor from Roast::Cog

Instance Method Details

#execute(input) ⇒ Object

: (Input) -> Output



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/roast/cogs/cmd.rb', line 274

def execute(input)
  config = @config #: as Config

  stdout_handler = config.show_stdout? ? ->(line) { $stdout.print(line) } : nil
  stderr_handler = config.show_stderr? ? ->(line) { $stderr.print(line) } : nil

  stdout, stderr, status = CommandRunner #: as untyped
    .execute(
      [input.command] + input.args,
      working_directory: config.valid_working_directory,
      stdin_content: input.stdin,
      stdout_handler: stdout_handler,
      stderr_handler: stderr_handler,
    )
  if !status.success? && config.fail_on_error?
    raise ControlFlow::FailCog, "Process exited with status code #{status.exitstatus}"
  end

  Output.new(stdout, stderr, status)
end