我想以某种方式要求用户说出他们的flickr_id,flickr_apikey之类的东西,但我很乐意在我的install命令下这样做,这样它就不会因为所有的参数而变得如此冗长和繁重。
所以就像这样
$ 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 also has to know you're flick api key, make one here ...
API Key: {here you should type your key}诸若此类?你明白我的意思了吗?你能做到吗?
发布于 2011-01-05 23:17:25
它确实可以!
您正在寻找ask。
举个例子:
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发布于 2014-10-25 14:15:04
也可以将颜色设置为符号
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'雷神可用颜色的完整列表,请访问:http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color
https://stackoverflow.com/questions/4604905
复制相似问题