class Kamaze::Project::Tools::Vagrant::Shell
Execute commands using “executable“
Options are passed to “Rake::FileUtilsExt.sh()“. Executable can be defined through “options“.
Attributes
options[R]
@return [Hash]
Public Class Methods
new(options = {})
click to toggle source
Initialize a shell with given options
@param [Hash] options
# File lib/kamaze/project/tools/vagrant/shell.rb, line 34 def initialize(options = {}) @options = options # Executable used by command @executable = options.delete(:executable) || :vagrant # default ``sh`` options @options[:verbose] = false unless options.key?(:verbose) end
Public Instance Methods
executable()
click to toggle source
Get (absolute) path to executable
Return “nil“ when executable CAN NOT be detected.
@return [String|nil]
# File lib/kamaze/project/tools/vagrant/shell.rb, line 53 def executable Cliver.detect(@executable)&.freeze end
executable?()
click to toggle source
@return [Boolean]
# File lib/kamaze/project/tools/vagrant/shell.rb, line 44 def executable? executable end
execute(*params, &block)
click to toggle source
Run given arguments as system command using “executable“.
# File lib/kamaze/project/tools/vagrant/shell.rb, line 68 def execute(*params, &block) env = preserved_env Bundler.with_clean_env do with_exit_on_failure do [env].concat(to_a.concat(params)).push(options).yield_self do |cmd| sh(*cmd, &block) self.retcode = self.shell_runner_last_status.exitstatus end end end end
to_a()
click to toggle source
@return [Array]
# File lib/kamaze/project/tools/vagrant/shell.rb, line 58 def to_a [executable] end
to_s()
click to toggle source
@return [String]
# File lib/kamaze/project/tools/vagrant/shell.rb, line 63 def to_s executable.to_s end
Protected Instance Methods
preserved_env(from = ENV)
click to toggle source
Get preserved env (from given env)
@param [ENV|Hash] from @return [Hash]
@todo refactor
# File lib/kamaze/project/tools/vagrant/shell.rb, line 90 def preserved_env(from = ENV) env = {} from = from.to_h ['SILENCE_DUPLICATE_DIRECTORY_ERRORS'].each do |key| next unless from.key?(key) env[key] = from.fetch(key) end env end