简体   繁体   中英

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?

Thor有一种询问用户输入的特定方法(毫不奇怪),名为ask

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM