11

我想以某种方式要求用户说出他们的 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}

等等?你明白这个想法,并且可以做到吗?

4

2 回答 2

20

确实可以!

您正在寻找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
于 2011-01-05T15:17:24.810 回答
5

也可以将颜色设置为符号

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

于 2014-10-25T06:15:03.567 回答