Module: Spielbash::CLI

Extended by:
CLI
Includes:
GLI::App
Included in:
Spielbash, CLI
Defined in:
lib/spielbash/view/cli.rb

Instance Method Summary collapse

Instance Method Details

#which(cmd) ⇒ Object

Cross-platform way of finding an executable in the $PATH.

which('ruby') #=> /usr/bin/ruby


16
17
18
19
20
21
22
23
24
25
# File 'lib/spielbash/view/cli.rb', line 16

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each {|ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return true if File.executable?(exe) && !File.directory?(exe)
    }
  end
  false
end