Created
October 10, 2008 19:31
-
-
Save dstrelau/16137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# module: abc | |
require 'rubygems' | |
require 'thor' | |
class Abc < Thor | |
desc 'debug', '' | |
def debug | |
puts "debug" | |
end | |
class Xyz < Thor | |
desc "debug", "namespaced task" | |
def debug | |
puts "~ XYZ namespace ~" | |
puts "debug" | |
end | |
end | |
def method_missing(meth, *args) | |
task = Thor["abc:#{meth.to_s}"] | |
task.parse task.klass.new, ARGV[1..-1] | |
end | |
end | |
Abc.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[abc] thor -T | |
The abc namespace doesn't have a `-T' task | |
Tasks | |
----- | |
abc:debug | |
abc:foo:bar do the bar | |
[abc] thor abc:debug | |
The abc namespace doesn't have a `abc:debug' task | |
tasks: | |
debug | |
help | |
[abc] thor abc:foo:bar | |
The abc namespace doesn't have a `abc:foo:bar' task | |
BAR! | |
tasks: | |
bar | |
help | |
[abc] ./abc.thor debug | |
tasks: | |
debug | |
help | |
[abc] ./abc.thor foo:bar | |
The abc namespace doesn't have a `foo:bar' task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# module: abc | |
require 'rubygems' | |
require 'thor' | |
class Abc < Thor | |
desc 'debug', '' | |
def debug | |
puts "tasks:" | |
puts self.class.tasks.map{|k,v| k} | |
end | |
class Foo < Thor | |
desc "bar", "do the bar" | |
def bar | |
puts "BAR!" | |
puts "tasks:" | |
puts self.class.tasks.map{|k,v| k} | |
end | |
end | |
end | |
Abc.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb | |
index 0a4a8ef..6772bf7 100644 | |
--- a/spec/thor_spec.rb | |
+++ b/spec/thor_spec.rb | |
@@ -5,6 +5,13 @@ class MyApp < Thor | |
map "-T" => :animal, ["-f", "--foo"] => :foo | |
+ class More < Thor | |
+ desc "stuff", "a namespaced task" | |
+ def stuff | |
+ true | |
+ end | |
+ end | |
+ | |
desc "zoo", "zoo around" | |
def zoo | |
true | |
@@ -135,6 +142,10 @@ describe "thor" do | |
lambda { MyApp.start(["what"]) }.must raise_error(NoMethodError, "the `what' task of MyApp is private") | |
end | |
+ it "calls a namespaced method" do | |
+ MyApp.start(["more:stuff"]).must == true | |
+ end | |
+ | |
it "provides useful help info for a simple method" do | |
capture(:stdout) { MyApp.start(["help"]) }.must =~ /zoo +zoo around/ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment