Method: Fulmar::Shell#run

Defined in:
lib/fulmar/shell.rb

#run(command, options = DEFAULT_OPTIONS) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fulmar/shell.rb', line 41

def run(command, options = DEFAULT_OPTIONS)
  reset_output(@last_output.max_size)
  command = [command] if command.class == String

  # is a custom path given?
  path = if options[:in]
           # is it absolute?
           (Pathname.new options[:in]).absolute? ? options[:in] : "#{@path}/#{options[:in]}"
         else
           @path
         end

  options[:error_message] ||= 'Last shell command returned an error.'

  command.unshift "cd \"#{path}\""

  # invoke a login shell?
  shell_command = shell_command(options[:login])

  @clean_environment << 'bundler' if options[:escape_bundler]

  if local?
    execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'", options[:error_message])
  else
    remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
    execute("ssh #{@host} '#{remote_command}'", options[:error_message])
  end
end