Class: CIHelper::Commands::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_helper/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ BaseCommand

Returns a new instance of BaseCommand.



20
21
22
# File 'lib/ci_helper/commands.rb', line 20

def initialize(**options)
  self.options = options
end

Class Method Details

.call!(**options) ⇒ Object



9
10
11
# File 'lib/ci_helper/commands.rb', line 9

def call!(**options)
  new(**options).call
end

.process_stdoutObject

:nocov:



14
15
16
# File 'lib/ci_helper/commands.rb', line 14

def process_stdout
  @process_stdout ||= $stdout
end

Instance Method Details

#execute(*commands) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ci_helper/commands.rb', line 29

def execute(*commands)
  command = commands.join(" && ")

  process_stdout.puts(Tools::Colorize.command(command))

  Open3.popen2e(command) do |_stdin, stdout, thread|
    stdout.each_char { |char| process_stdout.print(char) }
    exit_code = thread.value.exitstatus

    fail!("Bad exit code #{exit_code} for command #{command.inspect}") unless exit_code.zero?
    0
  end
end

#execute_with_env(*commands) ⇒ Object



24
25
26
27
# File 'lib/ci_helper/commands.rb', line 24

def execute_with_env(*commands)
  commands = ["export RAILS_ENV=#{env}", *commands] if env
  execute(*commands)
end