Module: Sevgi::Function::Shell
- Included in:
- Sevgi::Function
- Defined in:
- lib/sevgi/function/shell.rb
Defined Under Namespace
Instance Method Summary collapse
- #executable!(*args) ⇒ Object
- #executable?(program) ⇒ Boolean
- #sh ⇒ Object
- #sh!(*args, &block) ⇒ Object
Instance Method Details
#executable!(*args) ⇒ Object
16 17 18 19 |
# File 'lib/sevgi/function/shell.rb', line 16 def executable!(*args) program = args.first.split.first raise "Missing executable: #{program}" unless executable?(program) end |
#executable?(program) ⇒ Boolean
8 9 10 11 12 13 14 |
# File 'lib/sevgi/function/shell.rb', line 8 def executable?(program) executable_cache.fetch(program) do executable_cache[program] = ENV["PATH"].split(::File::PATH_SEPARATOR).any? do |dir| ::File.executable?(::File.join(dir, program)) end end end |
#sh!(*args, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sevgi/function/shell.rb', line 85 def sh!(*args, &block) executable!(*args) unless args.empty? sh(*args, &block).tap do |result| unless result.ok? warn(result.err) warn("") raise "Command failed: #{result.cmd}" end end end |