ruby Thor的交互提示

wvmv3b1j  于 11个月前  发布在  Ruby
关注(0)|答案(2)|浏览(86)

我想以某种方式要求用户说出他们的flickr_id,flickr_apikey和那些东西,但是id'最乐意在我的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}

字符串
等等?你明白这个想法吗?它能做到吗?

oxalkeyp

oxalkeyp1#

的确可以!
您正在寻找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

字符串

okxuctiv

okxuctiv2#

也可以将颜色设置为符号

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

相关问题