[英]Interactive prompt with thor
我想以某種方式要求用戶說出他們的 flickr_id、flickr_apikey 和那些東西,但我很樂意在我的安裝命令下這樣做,所以它不會因為所有參數而最終成為如此長而沉重的行。
所以像
$ 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}
等等? 你明白這個想法嗎,它可以做到嗎?
確實可以!
您正在尋找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
也可以將顏色設置為符號
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'
Thor 可用顏色的完整列表,在這里: http : //www.rubydoc.info/github/wycats/thor/Thor/Shell/Color
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.