与雷神互动提示

发布于 2024-10-10 15:04:57 字数 455 浏览 0 评论 0原文

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

?你明白这个想法了吗?可以实现吗?

I want to somehow ask the user to say their flickr_id, flickr_apikey and that stuff, but id' be most happy to do it under my install command so it dosn't end up being such a long and heavy line because of alle the arguments.

so something like

$ 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}

and so on? Do you get the idea, and can it be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她比我温柔 2024-10-17 15:04:57

确实可以!

您正在寻找询问

一个例子:

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

Indeed it can!

You are looking for ask.

An example:

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
风为裳 2024-10-17 15:04:57

还可以将颜色设置为符号

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

It's also possible to set color as a symbol

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'

Full list of available colors for Thor, here: http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文