Thor gem: how to display a USAGE: banner when passing in 0 arguments

N

Nick Klauer

[Note: parts of this message were removed to make it a legal post.]

So I can't find any good place to post this question, unless I'm filing it
as a bug to the gem authors. Before I do that, I'm hoping someone in this
group might know the answer.

With the Thor <http://rubygems.org/gems/thor> gem, it looks to do
almost everything I need to create a pretty rich command-line interface for
generating scaffolding for a project. I want to provide the user a "usage
banner" when they call the app without passing any arguments. I don't
know/can't find the documentation stating how this is configured in an app.
Does anyone have a simple code example that shows how this might be done?

class App < Thor

desc "do awesome stuff"
def awesomeifier
...
end

....

def no_args
# print some banner or something
end

end

App.start


-Nick Klauer
 
N

Nick Klauer

[Note: parts of this message were removed to make it a legal post.]

Okay, so it's not really explained in the README, but it's in the docs. I'm
not looking for a BANNER, i'm looking for
default_task<http://rdoc.info/github/wycats/thor/master/Thor.default_task>,
which I can output something useful with it:
http://rdoc.info/github/wycats/thor/master/Thor.default_task

So, say you have a class:

class App < Thor

desc "foo", "do foo things"
def foo
...
end

...
end

You want a default task? Well, you might also want to display the help
while you're at it:

class App < Thor

default_task :the_banner

desc "help", "my help, not Thor's"
def the_banner
puts <<-THING

You can put anything here, why not? This is a help doc, afterall.
THING
help # call help to tack on those useful Task descriptions
end
end

and when you run the thing from the command-line:

$ ruby app.rb

You can put anything here, why not? This is a help doc, afterall.
Tasks:
app.rb help # my help, not Thor's
app.rb help [TASK] # Describe available tasks or one specific task


<http://rdoc.info/github/wycats/thor/master/Thor.default_task>
-Nick Klauer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top