Skip to content

No displayable tasks when defined via code? #110

Closed
trans opened this Issue Apr 5, 2012 · 2 comments

2 participants

@trans
trans commented Apr 5, 2012

Hi, I've run into a problem where I am trying to define rake tasks via an alternative configuration file rather then in the usual Rakefile. While the task is defined and I can run it, it doesn't show up in the task list. I ran an irb session to verify this. This is it:

require 'rake'

desc 'testing...'
task :woot do
  puts "woot"
end

ra = Rake::Application.new
ra.options.show_tasks = :tasks
ra.display_tasks_and_comments 
=> []

Why are there no displayable tasks when I just defined one above?

@trans
trans commented Apr 9, 2012

Here is the real use case:

https://github.com/rubyworks/rc/blob/master/lib/rc/tweaks/rake.rb

Maybe someone can provide pointers if there are issues/better ways to handle this.

@jimweirich
Owner

Ok, first of all you are messing with internal Rake structures and methods and there is no guarantee that they will be remain constant between versions of rake. So, this issue will be closed.

That said, here's what you're doing wrong (at least for the current version of rake).

(1) You need to tell Rake to record the comment metadata. Otherwise it won't bother to store the comments.
(2) You need to set a task pattern to match against.
(3) You need to create the Rake application object BEFORE defining the tests, and to set your application up as the default application used by the DSL.

I think that's most of it.

Here's a version of the script that should work with the current Rake HEAD:

require 'rake'

Rake::TaskManager.record_task_metadata = true
ra = Rake::Application.new

Rake.application = ra

desc 'testing...'
t = task :woot do
  puts "woot"
end

ra.options.show_tasks = :tasks
ra.options.show_task_pattern = //
ra.display_tasks_and_comments
@jimweirich jimweirich closed this Oct 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.