Module: Bwrap::Execution
- Included in:
- Args::Bind, Args::Environment, Bwrap, Config::Features::Ruby, Resolvers::Library, Resolvers::Library::Base, Resolvers::Mime
- Defined in:
- lib/bwrap/execution.rb,
lib/bwrap/execution/labels.rb,
lib/bwrap/execution/execution.rb,
lib/bwrap/execution/exceptions.rb
Overview
Provides methods to execute commands and handle its output.
Output can be controlled by using log levels of Output module.
Defined Under Namespace
Modules: Labels, Path Classes: CommandError, CommandNotFound, Exec, Execute, ExecutionFailed, Logging, Popen2e
Class Method Summary collapse
-
.do_execute(command, **kwargs) ⇒ Object
Actual implementation of execution command.
-
.last_status ⇒ Object
Returns Process::Status instance of last execution.
-
.popen2e(*cmd, rootcmd: nil, config: nil, log_callback: 2, log: true, &block) ⇒ Object
Works similarly to Ruby’s official ‘Open3.popen2e`.
Methods included from Output
debug?, debug_output, error_output, handle_output_options, info_output, quiet?, trace?, trace_output, verb_output, verbose?, warn_output
Class Method Details
.do_execute(command, **kwargs) ⇒ Object
When an array is given as a command, empty strings are passed as empty arguments.
This means that ‘[ “foo”, “bar” ]` passes one argument to “foo” command, when `[ “foo”, “”, “bar” ]` passes two arguments.
This may or may not be what is assumed, so it can’t be fixed here. It is up to the command to decide how to handle empty arguments.
Actual implementation of execution command. Can be used when static method is needed.
Returns pid of executed command if wait is false. Returns command output if wait is true.
fail == If true, an error is raised in case the command returns failure code.
TODO: log kwarg could take log level as argument. Like :trace.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bwrap/execution/execution.rb', line 78 def self.do_execute command, **kwargs executor = Exec.new command executor.dry_run = @dry_run executor.clear_env = kwargs.key?(:clear_env) ? kwargs.delete(:clear_env) : false executor.config = kwargs.key?(:config) ? kwargs.delete(:config) : nil executor.direct_output = kwargs.key?(:direct_output) ? kwargs.delete(:direct_output) : false executor.env = kwargs.key?(:env) ? kwargs.delete(:env) : {} executor.error = kwargs.key?(:error) ? kwargs.delete(:error) : nil executor.fail = kwargs.key?(:fail) ? kwargs.delete(:fail) : true executor.log = kwargs.key?(:log) ? kwargs.delete(:log) : true executor.log_callback = kwargs.key?(:log_callback) ? kwargs.delete(:log_callback) : 1 executor.rootcmd = kwargs.key?(:rootcmd) ? kwargs.delete(:rootcmd) : nil executor.wait = kwargs.key?(:wait) ? kwargs.delete(:wait) : true unless kwargs.empty? raise ArgumentError, %{unknown keywords: #{kwargs.keys.join ","}} end executor.execute ensure @last_status = executor.last_status if executor&.last_status end |
.last_status ⇒ Object
This only is able to return the status if wait is true, as otherwise caller is assumed to
Returns Process::Status instance of last execution.
handle execution flow.
130 131 132 |
# File 'lib/bwrap/execution/execution.rb', line 130 def self.last_status @last_status end |
.popen2e(*cmd, rootcmd: nil, config: nil, log_callback: 2, log: true, &block) ⇒ Object
Works similarly to Ruby’s official ‘Open3.popen2e`.
A block is accepted, as does ‘Open3.popen2e`. For now, at least.
TODO: Verify default log_callback is correct
117 118 119 120 121 122 123 |
# File 'lib/bwrap/execution/execution.rb', line 117 def popen2e *cmd, rootcmd: nil, config: nil, log_callback: 2, log: true, &block popen = Bwrap::Execution::Popen2e.new rootcmd: rootcmd, config: config popen.dry_run = @dry_run # TODO: Add a test that tests that this works as it works with execute(). popen.popen2e(*cmd, log_callback: log_callback, log: log, &block) ensure @last_status = popen&.child_status end |