Search code examples
ruby-on-railsrubyinstallationthor

Interactive prompt with thor


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?


Solution

  • 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