Hello,
I'm working on a new Ant bundle (It's in the reviews section of the TM repository) and one of the commands invokes ant via ruby. Currently I'm warning users that ant is missing/not found using:
ant_version = `ant -version` if ant_version.nil? | ant_version.empty? puts "<h1>Error</h1>Ant was not found, please ensure that it has been installed and your $PATH is set correctly." exit end
but 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.
Thanks, Simon
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") abort end
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).
[...] Should probably be parameterized so we can later move it to a support library. Should maybe also check that the found file is executable.
I've altered it to the following which appears to work fine for me.
require SUPPORT + '/lib/exit_codes'
def require_cmd(cmd) exists = ENV['PATH'].split(':').any? { |dir| File.executable? File.join(dir, cmd) } unless exists puts '<h3 class="error">Couldn't find ‘' + cmd + '’</ h3><p>Locations searched:</p><p><pre>' puts ENV['PATH'].gsub(/:/, "\n") + '</pre></p>' TextMate.exit_show_html() end end
require_cmd "ant"
And would be nice if it also supported TM_ANT.
Agreed, I need to update the bundle to support TM_ANT. I'll add it to my TODO list.
Thank you, Simon