Class: Gitlab::QA::Docker::Shellout
- Inherits:
-
Object
- Object
- Gitlab::QA::Docker::Shellout
- Defined in:
- lib/gitlab/qa/docker/shellout.rb
Constant Summary collapse
- StatusError =
Class.new(StandardError)
Instance Method Summary collapse
-
#execute! ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(command) ⇒ Shellout
constructor
A new instance of Shellout.
Constructor Details
#initialize(command) ⇒ Shellout
Returns a new instance of Shellout.
11 12 13 14 15 16 17 |
# File 'lib/gitlab/qa/docker/shellout.rb', line 11 def initialize(command) @command = command @output = [] Rainbow.enabled = Runtime::Env.colorized_logs? Runtime::Logger.info("Docker shell command: `#{@command.mask_secrets}`".cyan) end |
Instance Method Details
#execute! ⇒ Object
rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/qa/docker/shellout.rb', line 19 def execute! # rubocop:disable Metrics/AbcSize raise StatusError, 'Command already executed' if @output.any? Open3.popen2e(@command.to_s) do |_in, out, wait| out.each do |line| @output.push(line) if block_given? yield line, wait else puts line end end if wait.value.exited? && wait.value.exitstatus.nonzero? # rubocop:disable Style/IfUnlessModifier raise StatusError, "Docker command `#{@command.mask_secrets}` failed! ✘" end end @output.join.chomp end |