Class: Fulmar::Shell
- Inherits:
-
Object
- Object
- Fulmar::Shell
- Defined in:
- lib/fulmar/shell.rb
Overview
Implements simple access to shell commands
Constant Summary collapse
- VERSION =
'1.4.0'
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#last_error ⇒ Object
Returns the value of attribute last_error.
-
#last_output ⇒ Object
Returns the value of attribute last_output.
-
#path ⇒ Object
Returns the value of attribute path.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#strict ⇒ Object
Returns the value of attribute strict.
Instance Method Summary collapse
-
#initialize(path = '.', host = 'localhost') ⇒ Shell
constructor
A new instance of Shell.
- #local? ⇒ Boolean
- #run(command, options = {}) ⇒ Object
Constructor Details
#initialize(path = '.', host = 'localhost') ⇒ Shell
Returns a new instance of Shell.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fulmar/shell.rb', line 13 def initialize(path = '.', host = 'localhost') @host = host @path = (path.nil? || path.empty?) ? '.' : path @path = File.(@path) if local? @last_output = [] @last_error = [] @debug = false @quiet = false @environment = {} @strict = false end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
10 11 12 |
# File 'lib/fulmar/shell.rb', line 10 def debug @debug end |
#last_error ⇒ Object
Returns the value of attribute last_error.
10 11 12 |
# File 'lib/fulmar/shell.rb', line 10 def last_error @last_error end |
#last_output ⇒ Object
Returns the value of attribute last_output.
10 11 12 |
# File 'lib/fulmar/shell.rb', line 10 def last_output @last_output end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def path @path end |
#quiet ⇒ Object
Returns the value of attribute quiet.
10 11 12 |
# File 'lib/fulmar/shell.rb', line 10 def quiet @quiet end |
#strict ⇒ Object
Returns the value of attribute strict.
10 11 12 |
# File 'lib/fulmar/shell.rb', line 10 def strict @strict end |
Instance Method Details
#local? ⇒ Boolean
49 50 51 |
# File 'lib/fulmar/shell.rb', line 49 def local? @host == 'localhost' end |
#run(command, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fulmar/shell.rb', line 25 def run(command, = {}) command = [command] if command.class == String # is a custom path given? if [:in] # is it absolute? path = [:in][0, 1] == '/' ? [:in] : "#{@path}/#{options[:in]}" else path = @path end command.unshift "cd #{path}" # invoke a login shell? shell_command = [:login] ? 'env -i bash -lc' : 'bash -c' if local? execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'") else remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'") execute("ssh #{@host} '#{remote_command}'") end end |