Module: SugarJar::Util
- Defined in:
- lib/sugarjar/util.rb
Class Method Summary collapse
-
.which(cmd) ⇒ Object
a mixin to hold stuff that Commands and RepoConfig both use.
-
.which_nofail(cmd) ⇒ Object
Finds the first entry in the path for a binary and checks to make sure it's not us.
Class Method Details
.which(cmd) ⇒ Object
a mixin to hold stuff that Commands and RepoConfig both use
8 9 10 11 12 13 14 |
# File 'lib/sugarjar/util.rb', line 8 def self.which(cmd) path = which_nofail(cmd) return path if path SugarJar::Log.fatal("Could not find #{cmd} in your path") exit(1) end |
.which_nofail(cmd) ⇒ Object
Finds the first entry in the path for a binary and checks to make sure it's not us. Warn if it is us as that won't work in 2.x
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sugarjar/util.rb', line 18 def self.which_nofail(cmd) ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir| p = File.join(dir, cmd) next unless File.exist?(p) && File.executable?(p) if File.basename(File.realpath(p)) == 'sj' SugarJar::Log.error( "'#{cmd}' is linked to 'sj' which is no longer supported.", ) next end return p end false end |