I want to somehow ask the user to say their flickr_id, flickr_apikey and that stuff, but id' be most happy to do it under my install command so it dosn't end up being such a long and heavy line because of alle the arguments.
so something like
$ thor PhotoonRails:install
We're about to install your system.. blaa, blaa, blaa...
We have to know you're Flick ID, get i here http://idgettr.com/
Flickr ID: {here you should type your id}
We a开发者_Go百科lso has to know you're flick api key, make one here ...
API Key: {here you should type your key}
and so on? Do you get the idea, and can it be done?
Indeed it can!
You are looking for ask
.
An example:
class PhotoonRails < Thor
desc "install", "install my cool stuff"
def install
say("We're about to install your system.. blaa, blaa, blaa... We have to know you're Flick ID, get i here http://idgettr.com")
flickr_id = ask("Flickr ID: ")
say("We also has to know you're flick api key, make one here ...")
flickr_api_key = ask("API Key: ")
# validate flickr creds
# do cool stuff
say("Complete!", GREEN)
end
end
It's also possible to set color as a symbol
say "Caution!", :yellow
ask 'Agreed?', :bold
# Choose limit:
ask "We have noticed.", :green, limited_to: ['proceed', 'exit']
# Default value (possible without :blue)
ask 'Type app name', :blue, default: 'blog'
Full list of available colors for Thor, here: http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color
精彩评论