简体   繁体   English

带有空白的Ruby Thor选项

[英]Ruby Thor options with white space

for an assignment I am doing I am required to have an option "--format oneline" where my output is formatted in one line. 对于我正在做的作业,我需要有一个选项“ --format oneline”,其中我的输出格式为一行。

I have successfully done this, but only if I use --formatoneline (without the white space). 我已成功完成此操作,但前提是我使用了--formatoneline(无空格)。 If I include the white space it seperates the option into 2 arguments ["format", "oneline"]. 如果我包含空格,它将选项分成2个参数[“ format”,“ oneline”]。

I'd like to know how to deal with the white space character here, as the assignment requires very specific formatting. 我想知道这里如何处理空白字符,因为分配要求非常特殊的格式。

This is coded using ruby and the Thor Module. 这是使用ruby和Thor模块进行编码的。

Thanks! 谢谢!

Jack 插口

You can specify :type for an option. 您可以为选项指定:type Take a look here. 在这里看看

method_option :format, type: :string

And then you can check if there is --format oneline 然后您可以检查是否存在--format oneline

if options[:format] == 'oneline'
   # puts smth
end

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

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