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.8.0'- DEFAULT_BUFFER_SIZE =
1000- DEFAULT_OPTIONS =
{ login: false, escape_bundler: false }
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#interactive ⇒ Object
Returns the value of attribute interactive.
-
#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
- #buffer_size(size) ⇒ Object
-
#initialize(path = '.', host = 'localhost') ⇒ Shell
constructor
A new instance of Shell.
- #local? ⇒ Boolean
- #run(command, options = DEFAULT_OPTIONS) ⇒ Object
Constructor Details
#initialize(path = '.', host = 'localhost') ⇒ Shell
Returns a new instance of Shell.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fulmar/shell.rb', line 21 def initialize(path = '.', host = 'localhost') @host = host.nil? ? 'no_hostname_set' : host @path = (path.nil? || path.empty?) ? '.' : path @path = File.(@path) if local? reset_output @debug = false @quiet = true @strict = false @interactive = false @clean_environment = [] # list of things to clean from environment variables end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def debug @debug end |
#interactive ⇒ Object
Returns the value of attribute interactive.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def interactive @interactive end |
#last_error ⇒ Object
Returns the value of attribute last_error.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def last_error @last_error end |
#last_output ⇒ Object
Returns the value of attribute last_output.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def last_output @last_output end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/fulmar/shell.rb', line 12 def path @path end |
#quiet ⇒ Object
Returns the value of attribute quiet.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def quiet @quiet end |
#strict ⇒ Object
Returns the value of attribute strict.
11 12 13 |
# File 'lib/fulmar/shell.rb', line 11 def strict @strict end |
Instance Method Details
#buffer_size(size) ⇒ Object
75 76 77 |
# File 'lib/fulmar/shell.rb', line 75 def buffer_size(size) reset_output(size) end |
#local? ⇒ Boolean
67 68 69 |
# File 'lib/fulmar/shell.rb', line 67 def local? @host == 'localhost' end |
#run(command, options = DEFAULT_OPTIONS) ⇒ Object
38 39 40 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 |
# File 'lib/fulmar/shell.rb', line 38 def run(command, = DEFAULT_OPTIONS) reset_output(@last_output.max_size) 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 [:error_message] ||= 'Last shell command returned an error.' command.unshift "cd \"#{path}\"" # invoke a login shell? shell_command = shell_command([:login]) @clean_environment << 'bundler' if [:escape_bundler] if local? execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'", [:error_message]) else remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'") execute("ssh #{@host} '#{remote_command}'", [:error_message]) end end |