Search code examples
rubythor

Ruby console app - gets.chomp on Thor


Im writing a small app to perform some tasks on the terminal. Thor gem does it very well while i have "one shot" commands. But one of my tasks need the user to input something after the command, then i tried unsuccessfully to use the gets.chomp:

class Devop < Thor
    desc "some", "string"
    def envstatus(pattern)
        # CODE ..
        while not (0..env_count).include?(option) do option = gets.chomp.to_i end
        # ..CODE
    end
end

when trying to run the command like this:

ruby devop.rb envstatus prtarq

i get this error:

devop.rb:40:in `gets': No such file or directory @ rb_sysopen - envstatus (Errno::ENOENT)

Seems like Thor took the channel and even queued my args there..

How can get some user input inside the Thor command?


Solution

  • Thor has a specific method for asking user input, (no surprise) named ask.