0
我有一个创建电子邮件,我想要做的是当给出-t
标志,并且没有参数与标志,默认的东西给一个程序给定没有,相反,它输出平时:<main>': missing argument: -t (OptionParser::MissingArgument)
如何默认信息,如果是使用optparse
所以我的问题的存在,如果我有这样的标志:
require 'optparse'
OPTIONS = {}
OptionParser.new do |opts|
opts.on('-t INPUT', '--type INPUT', 'Specify who to say hello to'){ |o| OPTIONS[:type] = o }
end.parse!
def say_hello
puts "Hello #{OPTIONS[:type]}"
end
case
when OPTIONS[:type]
say_hello
else
puts "Hello World"
end
,我跑没有必需的参数INPUT
这个标志我如何让程序出把Hello World
代替:<main>': missing argument: -t (OptionParser::MissingArgument)
?
实例:
C:\Users\bin\ruby\test_folder>ruby opt.rb -t hello
Hello hello
C:\Users\bin\ruby\test_folder>ruby opt.rb -t
opt.rb:7:in `<main>': missing argument: -t (OptionParser::MissingArgument)
C:\Users\bin\ruby\test_folder>