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

clear, #command, #get_config, #host_inventory, #initialize, instance, #os_info, #set_config, #set_example, #stderr_handler=, #stdout_handler=

Constructor Details

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

Instance Method Details

#build_command(cmd) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/specinfra/backend/exec.rb', line 32

def build_command(cmd)
  shell = get_config(:shell) || '/bin/sh'
  cmd = cmd.shelljoin if cmd.is_a?(Array)
  shell = shell.shellescape

  if get_config(:interactive_shell)
    shell << " -i"
  end

  if get_config(:login_shell)
    shell << " -l"
  end

  cmd = "#{shell} -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



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

def run_command(cmd, opts={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  stdout, stderr, exit_status = with_env do
    spawn_command(cmd)
  end

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

  CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exit_status
end

#send_directory(from, to) ⇒ Object



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

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

#send_file(from, to) ⇒ Object



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

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