Skip to content

Commit

Permalink
Merge 4929c95 into 577fcc4
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmeyer committed Dec 18, 2013
2 parents 577fcc4 + 4929c95 commit 39b2ff0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/thor/invocation.rb
Expand Up @@ -25,6 +25,11 @@ def initialize(args = [], options = {}, config = {}, &block) #:nodoc:
super
end

# Make the current command chain accessible with in a Thor-(sub)command
def current_command_chain
@_invocations.values.flatten.map(&:to_sym)
end

# Receives a name and invokes it. The name can be a string (either "command" or
# "namespace:command"), a Thor::Command, a Class or a Thor instance. If the
# command cannot be guessed by name, it can also be supplied as second argument.
Expand Down
13 changes: 13 additions & 0 deletions spec/fixtures/invoke.thor
Expand Up @@ -116,3 +116,16 @@ class H < Thor::Group
class_option :defined, :type => :boolean, :default => true
invoke_from_option :defined
end

class I < Thor
desc "two", "Two"
def two
current_command_chain
end
end

class J < Thor
desc "i", "I"
subcommand :one, I
end

14 changes: 13 additions & 1 deletion spec/invocation_spec.rb
Expand Up @@ -58,7 +58,19 @@
expect(A.new([], :defaulted_value => 'not default').invoke('b:four')).to eq('not default')
end

it 'dump configuration values to be used in the invoked class' do
it "returns the command chain" do
expect(I.new.invoke("two")).to eq([ :two ])

if RUBY_VERSION < '1.9.3'
result = J.start(["one", "two" ])
expect(result).to include(:one)
expect(result).to include(:two)
else
expect(J.start(["one", "two" ])).to eq([ :one, :two ])
end
end

it "dump configuration values to be used in the invoked class" do
base = A.new
expect(base.invoke('b:three').shell).to eq(base.shell)
end
Expand Down

0 comments on commit 39b2ff0

Please sign in to comment.