Class: Specinfra::Backend::Exec

Inherits:
Base
  • Object
show all
Defined in:
lib/specinfra/backend/exec.rb

Direct Known Subclasses

Docker, Lxc, Ssh, Telnet

Instance Method Summary collapse

Methods inherited from Base

#command, #get_config, #host_inventory, #initialize, instance, #os_info, #set_config, #set_example

Constructor Details

This class inherits a constructor from Specinfra::Backend::Base

Instance Method Details

#build_command(cmd) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/specinfra/backend/exec.rb', line 33

def build_command(cmd)
  shell = get_config(:shell) || '/bin/sh'
  cmd = cmd.shelljoin if cmd.is_a?(Array)
  cmd = "#{shell.shellescape} -c #{cmd.to_s.shellescape}"

  path = get_config(:path)
  if path
    cmd = %Q{env PATH="#{path}" #{cmd}}
  end

  cmd
end

#run_command(cmd, opts = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/specinfra/backend/exec.rb', line 8

def run_command(cmd, opts={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  stdout = with_env do
    `#{build_command(cmd)} 2>&1`
  end
  # In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
  # stdout, stderr, status = Open3.capture3(cmd)

  if @example
    @example.[:command] = cmd
    @example.[:stdout]  = stdout
  end

  CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus
end

#send_directory(from, to) ⇒ Object


29
30
31
# File 'lib/specinfra/backend/exec.rb', line 29

def send_directory(from, to)
  FileUtils.cp_r(from, to)
end

#send_file(from, to) ⇒ Object


25
26
27
# File 'lib/specinfra/backend/exec.rb', line 25

def send_file(from, to)
  FileUtils.cp(from, to)
end