Class: XcodeArchiveCache::Shell::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/shell/executor.rb

Instance Method Summary collapse

Instance Method Details

#execute(command, print_command = false) ⇒ Boolean

Returns true if command succeeded and returned 0, false otherwise.

Parameters:

  • command (String)
  • print_command (Boolean) (defaults to: false)

Returns:

  • (Boolean)

    true if command succeeded and returned 0, false otherwise



26
27
28
29
30
31
32
# File 'lib/shell/executor.rb', line 26

def execute(command, print_command = false)
  actual_command = extend_for_pipefail(command, print_command)
  result = system actual_command

  return false if result == nil
  result
end

#execute_for_output(command, print_command = false) ⇒ String

Parameters:

  • command (String)
  • print_command (Boolean) (defaults to: false)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
# File 'lib/shell/executor.rb', line 10

def execute_for_output(command, print_command = false)
  actual_command = extend_for_pipefail(command, print_command)
  output, status = Open3.capture2e(actual_command)

  if status.exitstatus != 0
    raise XcodeArchiveCache::Informative, "#{command}\nexecution failed\n#{output}"
  end

  output
end

#execute_with_env(command, env) ⇒ Boolean

Returns true if command succeeded and returned 0, false otherwise.

Parameters:

  • command (String)
  • env (Hash)

Returns:

  • (Boolean)

    true if command succeeded and returned 0, false otherwise



39
40
41
42
43
44
# File 'lib/shell/executor.rb', line 39

def execute_with_env(command, env)
  result = system(env, "set -x && '#{command}'")

  return false if result == nil
  result
end