Class: SystemCommand Private
- Inherits:
-
Object
- Object
- SystemCommand
- Extended by:
- Predicable
- Includes:
- Context
- Defined in:
- Library/Homebrew/system_command.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.
Class for running sub-processes and capturing their output and exit status.
Defined Under Namespace
Modules: Mixin Classes: Result
Instance Attribute Summary collapse
- #pid ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object private
-
#initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false, print_stdout: false, print_stderr: true, verbose: false, secrets: [], **options) ⇒ SystemCommand
constructor
private
A new instance of SystemCommand.
- #run! ⇒ Object private
Methods included from Predicable
Methods included from Context
current, current=, #debug?, #quiet?, #with_context
Constructor Details
#initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false, print_stdout: false, print_stderr: true, verbose: false, secrets: [], **options) ⇒ SystemCommand
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 a new instance of SystemCommand.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'Library/Homebrew/system_command.rb', line 63 def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false, print_stdout: false, print_stderr: true, verbose: false, secrets: [], **) require "extend/ENV" @executable = executable @args = args @sudo = sudo @input = Array(input) @print_stdout = print_stdout @print_stderr = print_stderr @verbose = verbose @secrets = (Array(secrets) + ENV.sensitive_environment.values).uniq @must_succeed = must_succeed .assert_valid_keys!(:chdir) @options = @env = env @env.each_key do |name| next if /^[\w&&\D]\w*$/.match?(name) raise ArgumentError, "Invalid variable name: '#{name}'" end end |
Instance Attribute Details
#pid ⇒ 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.
32 33 34 |
# File 'Library/Homebrew/system_command.rb', line 32 def pid @pid end |
Class Method Details
.run(executable, **options) ⇒ Object
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.
34 35 36 |
# File 'Library/Homebrew/system_command.rb', line 34 def self.run(executable, **) new(executable, **).run! end |
.run!(command, **options) ⇒ Object
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.
38 39 40 |
# File 'Library/Homebrew/system_command.rb', line 38 def self.run!(command, **) run(command, **, must_succeed: true) end |
Instance Method Details
#command ⇒ Object
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.
86 87 88 |
# File 'Library/Homebrew/system_command.rb', line 86 def command [*sudo_prefix, *env_args, executable.to_s, *] end |
#run! ⇒ Object
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'Library/Homebrew/system_command.rb', line 42 def run! puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || debug? @output = [] each_output_line do |type, line| case type when :stdout $stdout << line if print_stdout? @output << [:stdout, line] when :stderr $stderr << line if print_stderr? @output << [:stderr, line] end end result = Result.new(command, @output, @status, secrets: @secrets) result.assert_success! if must_succeed? result end |