lib/fulmar/shell.rb in fulmar-shell-1.6.7 vs lib/fulmar/shell.rb in fulmar-shell-1.7.0
- old
+ new
@@ -3,13 +3,13 @@
# This shell is part of the fulmar deployment tools
# it can be used stand-alone, though
module Fulmar
# Implements simple access to shell commands
class Shell
- VERSION = '1.6.7'
+ VERSION = '1.7.0'
- attr_accessor :debug, :last_output, :last_error, :quiet, :strict
+ attr_accessor :debug, :last_output, :last_error, :quiet, :strict, :interactive
attr_reader :path
DEFAULT_OPTIONS = {
login: false,
escape_bundler: false
@@ -22,13 +22,19 @@
@last_output = []
@last_error = []
@debug = false
@quiet = true
@strict = false
+ @interactive = false
@clean_environment = [] # list of things to clean from environment variables
end
+ def interactive=(interactive)
+ @interactive = interactive
+ @quiet = false if interactive
+ end
+
def run(command, options = DEFAULT_OPTIONS)
reset_output
command = [command] if command.class == String
# is a custom path given?
@@ -89,11 +95,25 @@
def path_without_bundler
ENV['PATH'].split(':').reject { |path| path.include?('ruby') || path.include?('gems') }.join(':')
end
- # Run the command and capture the output
def execute(command, error_message)
+ if @interactive
+ execute_interactive(command, error_message)
+ else
+ execute_quiet(command, error_message)
+ end
+ end
+
+ def execute_interactive(command, error_message)
+ unless system(command)
+ puts "\n\n#{error_message}"
+ end
+ end
+
+ # Run the command and capture the output
+ def execute_quiet(command, error_message)
# Ladies and gentleman: More debug, please!
puts command if @debug
return_value = -1
Open3.popen3(environment, command) do |_stdin, stdout, stderr, wait_thread|