与托尔互动提示

时间:2011-01-05 14:05:44

标签: ruby-on-rails ruby installer 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}

等等?你明白这个想法吗?可以吗?

2 个答案:

答案 0 :(得分:18)

确实可以!

您正在寻找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

答案 1 :(得分:4)

也可以将颜色设置为符号

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, deafult: 'blog'

Thor的可用颜色的完整列表,在此处:http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color