有没有办法让雷神有两个互斥的选项?例如,我需要提供一个列表选项。我可能有一个选项-l ent1 ent2 ent3 ent67,也可能有一个选项-f,我传递一个带有contents ent1 ent2 ent3 ent67的文件。这两个选项可以在不在方法中编写额外处理代码的情况下与Thor互斥吗?
发布于 2013-10-06 05:37:14
我还没有找到一种内置的方法来做到这一点,但是你可以通过你自己的简单检查来完成它。下面是一个示例Thor命令,它可以执行您想要的操作。
desc "command", "A command that does something."
option :list, aliases: 'l', type: :array
option :file, aliases: 'f'
def list
if options[:list] && options[:file]
puts "Use only one, --list(-l) or --file(-f)"
exit(0)
end
# Place the functions of the command here
end希望这能有所帮助!
https://stackoverflow.com/questions/15586955
复制相似问题