Module: Sevgi::Function::Shell

Included in:
Sevgi::Function
Defined in:
lib/sevgi/function/shell.rb

Defined Under Namespace

Classes: Result, Runner

Instance Method Summary collapse

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

Returns:

  • (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

#shObject



83
# File 'lib/sevgi/function/shell.rb', line 83

def sh(...) = Runner.new.(...)

#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