11

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?

user229044
  • 232,980
  • 40
  • 330
  • 338
Oluf Nielsen
  • 769
  • 1
  • 8
  • 24

2 Answers2

21

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
Cyril
  • 38
  • 5
hornairs
  • 1,707
  • 13
  • 20
5

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

jethro
  • 168
  • 3
  • 13
itsnikolay
  • 17,415
  • 4
  • 65
  • 64