Class: R10K::Util::Subprocess Private
- Inherits:
-
Object
- Object
- R10K::Util::Subprocess
- Includes:
- Logging
- Defined in:
- lib/r10k/util/subprocess.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The subprocess namespace implements an interface similar to childprocess. The interface has been simplified to make it easier to use and does not depend on native code.
Defined Under Namespace
Classes: Result, Runner, SubprocessError
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #argv ⇒ Object readonly private
-
#cwd ⇒ String
The directory to be used as the cwd when executing the command.
- #logger ⇒ Object writeonly private
-
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
Class Method Summary collapse
-
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
private
Class < R10K::Util::Subprocess::Runner].
Instance Method Summary collapse
-
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
-
#initialize(argv) ⇒ Subprocess
constructor
private
Prepare the subprocess invocation.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(argv) ⇒ Subprocess
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare the subprocess invocation.
51 52 53 54 55 |
# File 'lib/r10k/util/subprocess.rb', line 51 def initialize(argv) @argv = argv @raise_on_fail = false end |
Instance Attribute Details
#argv ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/r10k/util/subprocess.rb', line 30 def argv @argv end |
#cwd ⇒ String
Returns The directory to be used as the cwd when executing the command.
41 42 43 |
# File 'lib/r10k/util/subprocess.rb', line 41 def cwd @cwd end |
#logger=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/r10k/util/subprocess.rb', line 46 def logger=(value) @logger = value end |
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
36 37 38 |
# File 'lib/r10k/util/subprocess.rb', line 36 def raise_on_fail @raise_on_fail end |
Class Method Details
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Class < R10K::Util::Subprocess::Runner].
18 19 20 21 22 23 24 |
# File 'lib/r10k/util/subprocess.rb', line 18 def self.runner if R10K::Util::Platform.windows? R10K::Util::Subprocess::Runner::Windows else R10K::Util::Subprocess::Runner::POSIX end end |
Instance Method Details
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/r10k/util/subprocess.rb', line 63 def execute subprocess = self.class.runner.new(@argv) subprocess.cwd = @cwd if @cwd logmsg = "Starting process: #{@argv.inspect}" logmsg << "(cwd: #{@cwd})" if @cwd logger.debug2(logmsg) result = subprocess.run logger.debug2("Finished process:\n#{result.format}") if @raise_on_fail && result.failed? raise SubprocessError.new("Command exited with non-zero exit code", :result => result) end result end |