marcamillion marcamillion - 1 year ago 87
Ruby Question

Don't know how to build task -- for parent task that calls other tasks

I have a rake task called

, that looks like this:

load './lib/tasks/fetch_and_create_snippets.rake'
load './lib/tasks/generate_diffs_for_snippets.rake'
load './lib/tasks/cleanup_snippets_with_empty_diffs.rake'

desc "Setup a new set of Snippets"
task :setup_a_new_set_of_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
repo = args[:repo]
path = args[:path]
entry_id = args[:entry_id]
framework_id = args[:framework_id]
method_name = args[:method_name]

I am calling it like this:

$ rake setup_a_new_set_of_snippets["some/repo","some/viable/path",1,1,has_many]
** Invoke setup_a_new_set_of_snippets (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute setup_a_new_set_of_snippets
rake aborted!
Don't know how to build task 'fetch_and_create_snippets[some/repo,some/viable/path,1,1,has_many]' (see --tasks)
/lib/tasks/setup_new_snippet_set.rake:12:in `block in <top (required)>'
/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/bin/ruby_executable_hooks:15:in `eval'
/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => setup_a_new_set_of_snippets
(See full trace by running task with --trace)

This is the task it gets hung up on:

desc 'Fetch and Create Snippets from Github'

task :fetch_and_create_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
# truncated for brevity

FWIW, when I run the
task by works like a charm.

What could be causing this?

Answer Source

You're not passing arguments to the rake task correctly. See How do I pass command line arguments to a rake task?

Specifically, right here:


it looks like you're using the syntax for Rake.application.invoke_task whereas the proper syntax for Rake::Task[name].invoke would be:

Rake::Task["fetch_and_create_snippets"].invoke(repo, path, entry_id, framework_id, method_name)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download