Method: Mixin::Shell#which

Defined in:
lib/fox/interface/thor/mixin/shell.rb

#which(command) ⇒ Boolean Also known as: exists?

Returns boolean true if command is available, false if not

Parameters:

  • command (String)

    Shell command string with or without arguments. If arguments are given, they are split on first whitespace and discarded

Returns:

  • (Boolean)

    Returns boolean true if command is available, false if not



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fox/interface/thor/mixin/shell.rb', line 90

def which command
  result      = false

  begin
    partial   = command.to_s
    partial   = partial.split(' ').first.to_s if( partial =~ %r{ }i )
    path      = File.which( partial )

    result    = true unless( path.nil? )
  rescue Exception => e
    say "(EE) " + e.message, :red
    result    = false
  end

  return result
end