有没有办法让Thor有两个互斥的选项?例如,我需要提供一个列表的选项。我可能有一个选项-l ent1 ent2 ent3 ent67
,我可能会选择-f
,我会传递一个内容为ent1 ent2 ent3 ent67
的文件。这两个选项是否可以与Thor互斥,而无需在方法中编写额外的处理代码?
答案 0 :(得分:3)
我还没有找到这样做的内置方法,但您可以通过自己的简单检查来完成它。这是一个示例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
希望这有帮助!