Skip to content

Instantly share code, notes, and snippets.

@wuputah
Created June 13, 2012 06:09
Show Gist options
  • Save wuputah/2922172 to your computer and use it in GitHub Desktop.
Save wuputah/2922172 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$task_to_check = ARGV[0]
begin
require 'rake'
rescue LoadError => e
exit(4)
end
Rake.application.options.rakelib = ['rakelib']
begin
Rake.application.raw_load_rakefile
rescue Exception => e
if e.is_a?(RuntimeError) && e.message =~ /^No Rakefile found/
exit(5)
end
exit(2)
end
unless Rake::Task.task_defined?($task_to_check)
exit(3)
end
exit(0)
__END__
exit codes:
0: task exists
1: this script raised an uncaught exception (from line 11)
2: exception while loading rakefile (app has a bug or depends on env)
3: Task doesnt exist
4: rake not present
5: rakefile not present
problems:
* The rakelib workaround might not work in all versions of rake
* Rake.application.raw_load_rakefile is not a public API for rake
* Brittle error message checking for exit code 5
* $PWD probably matters; might need to chdir() to the right directory first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment