Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

A task can be recalled many times from the same task-caller #224

Closed
wants to merge 1 commit into from

2 participants

@helios
class Caller < Thor
  desc "fake DATA", "fake caller"
  def fake(data)
     puts "#{data}"
  end

  desc "foo INFO", "foo main caller"
  def foo(info)
    invoke :fake, ["Pippo #{info}"]
    invoke :fake, ["Pluto #{info}"]
  end
end

Without patch:

thor caller:foo Duck
=> Pippo Duck

with patch:

=> Pippo Duck
=> Pluto Duck
@eventualbuddha
Collaborator

Why do you want to do this? Having invoke only call a given task once is intentional. If you want to call it multiple times, why not simply call fake "Pippo #{info}" and fake "Pluto #{info}"? Please reopen if there's something I'm not understanding about what you're trying to do. Cheers!

@helios

How can I access to options if I call the method directly ?

@eventualbuddha
Collaborator

Can't you simply access options in the other method?

@helios

are you sure you can ? I can't, could you try to use (call) options from a method/task called without invoke ?

@eventualbuddha
Collaborator

Works for me:

class Caller < Thor
  desc "fake DATA", "fake caller"
  def fake(data)
    puts "fake() options=#{options.inspect}"
    puts "#{data}"
  end

  desc "foo INFO", "foo main caller"
  method_options :a => :boolean
  def foo(info)
    puts "foo() options=#{options.inspect}"
    fake "Pippo #{info}"
    fake "Pluto #{info}"
  end
end
$ thor caller:foo -a bees
foo() options={"a"=>true}
fake() options={"a"=>true}
Pippo bees
fake() options={"a"=>true}
Pluto bees
@helios

right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2012
  1. @helios
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/thor/invocation.rb
View
2  lib/thor/invocation.rb
@@ -117,8 +117,8 @@ def invoke_task(task, *args) #:nodoc:
unless current.include?(task.name)
current << task.name
- task.run(self, *args)
end
+ task.run(self, *args)
end
# Invoke all tasks for the current instance.
Something went wrong with that request. Please try again.