lib/fulmar/shell.rb in fulmar-shell-1.7.0 vs lib/fulmar/shell.rb in fulmar-shell-1.8.0

- old
+ new

@@ -1,28 +1,30 @@ require 'open3' +require 'fulmar/ringbuffer' # 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.7.0' + VERSION = '1.8.0' attr_accessor :debug, :last_output, :last_error, :quiet, :strict, :interactive attr_reader :path + DEFAULT_BUFFER_SIZE = 1000 + DEFAULT_OPTIONS = { login: false, escape_bundler: false } def initialize(path = '.', host = 'localhost') @host = host.nil? ? 'no_hostname_set' : host @path = (path.nil? || path.empty?) ? '.' : path @path = File.expand_path(@path) if local? - @last_output = [] - @last_error = [] + reset_output @debug = false @quiet = true @strict = false @interactive = false @clean_environment = [] # list of things to clean from environment variables @@ -32,11 +34,11 @@ @interactive = interactive @quiet = false if interactive end def run(command, options = DEFAULT_OPTIONS) - reset_output + reset_output(@last_output.max_size) command = [command] if command.class == String # is a custom path given? if options[:in] # is it absolute? @@ -68,14 +70,18 @@ def path=(path) @path = local? ? File.expand_path(path) : path end + def buffer_size(size) + reset_output(size) + end + protected - def reset_output - @last_output = [] - @last_error = [] + def reset_output(size = DEFAULT_BUFFER_SIZE) + @last_output = Fulmar::RingBuffer.new(size) + @last_error = Fulmar::RingBuffer.new(size) end def shell_command(login) login ? "env -i HOME=\"#{ENV['HOME']}\" LANG=\"#{ENV['LANG']}\" bash -lc" : 'bash -c' end