Class: Covalence::PopenWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/covalence/core/cli_wrappers/popen_wrapper.rb

Class Method Summary collapse

Class Method Details

.loggerObject



57
58
59
# File 'lib/covalence/core/cli_wrappers/popen_wrapper.rb', line 57

def logger
  Covalence::LOGGER
end

.run(cmds, path, args, stdin_io: STDIN, stdout_io: STDOUT, stderr_io: STDERR, debug: Covalence::DEBUG_CLI, dry_run: false, ignore_exitcode: false, workdir: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/covalence/core/cli_wrappers/popen_wrapper.rb', line 10

def run(cmds, path, args,
        stdin_io: STDIN,
        stdout_io: STDOUT,
        stderr_io: STDERR,
        debug: Covalence::DEBUG_CLI,
        dry_run: false,
        ignore_exitcode: false,
        workdir: nil)

  # TODO: implement path prefix for the docker runs, see @tf_cmd
  cmd_string = [*cmds]
  # TODO: cmd escape issues with -var.
  cmd_string += [*args] unless args.blank?
  cmd_string << path unless workdir

  #TODO debug command string maybe
  #TODO debug command args maybe

  run_cmd = cmd_string.join(' ')
  print_cmd_string(run_cmd)
  if dry_run
    run_cmd = Covalence::DRY_RUN_CMD
  end

  if debug
    return 0 unless HighLine.new.agree('Execute? [y/n]')
  end

  if workdir
    spawn_subprocess(ENV, run_cmd,
                     stdin_io: stdin_io,
                     stdout_io: stdout_io,
                     stderr_io: stderr_io,
                     ignore_exitcode: ignore_exitcode,
                     path: path,
                     workdir: workdir)
  else
    spawn_subprocess(ENV, run_cmd,
                     stdin_io: stdin_io,
                     stdout_io: stdout_io,
                     stderr_io: stderr_io,
                     ignore_exitcode: ignore_exitcode,
                     path: path)
  end

end