简体   繁体   English

Ruby控制台应用程序-Thor上的gets.chomp

[英]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. 当我执行“一次射击”命令时, Thor gem的性能非常好。 But one of my tasks need the user to input something after the command, then i tried unsuccessfully to use the gets.chomp: 但是我的任务之一是需要用户在命令后输入一些内容,然后我尝试使用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.. 好像雷神(Thor)进入了频道,甚至把我的args在那里排队

How can get some user input inside the Thor command? 如何在Thor命令中获得一些用户输入?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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