[英]Ask required command-line input in Rails-Generator/Thor
I am building a generator in Ruby-on-Rails and was wondering if it's possible to ask for a required argument with Thor . 我正在Ruby-on-Rails中构建生成器,并且想知道是否可以与Thor一起请求必需的参数。 Or if there's a decent workaround.
或者,如果有不错的解决方法。 Right now I'm just raising an exception:
现在,我只是提出一个例外:
@foo = ask('[Required] Enter Foo:')
raise 'Required argument missing' unless (@foo).present?
A workaround could be: 解决方法可能是:
loop do
@foo = ask('[Required] Enter Foo:')
break if @foo.present?
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.