[TxMt] Ruby require_cmd equivalent.

Allan Odgaard throw-away-2 at macromates.com
Thu Nov 1 17:56:30 UTC 2007

On 31 Oct 2007, at 19:49, Simon Gregory wrote:

> [...] this isn't quite as elegant as the TM shell script require_cmd  
> (ruby prints the cmd not found error, and it takes a fraction longer  
> for ant to start up). Is there an equivalent I should be using with  
> ruby? If not is there a better way this could be achieved.

We don’t have a Ruby equivalent, but it would go something like this:

     exists = ENV['PATH'].split(':').any? { |dir| File.exists?  
File.join(dir, 'ant') }
     unless exists
       puts "Couldn’t find ‘ant’. Locations searches:"
       puts ENV['PATH'].gsub(/:/, "\n")

Should probably be parameterized so we can later move it to a support  
library. Should maybe also check that the found file is executable.  
And would be nice if it also supported TM_ANT.

Speaking of the latter, it is not uncommon that users set e.g. TM_SVN  
to the *folder* containing svn, not the full path. Either we should  
allow that, or we should test against it (not directly related to the  
above, just thinking out loud).

More information about the textmate mailing list