Here's one way to do it, but it requires for the -f
and -d
options to be specified on the command line before the -a
option:
(let [opts [["-a" nil "something"
:id :a
:assoc-fn (fn [opts opt-id val]
(assoc opts opt-id
(if (and (:file opts) (:dir opts))
val
::missing-required)))
:validate [#(not= % ::missing-required)
"Missing required -f and -d options"]
:post-validation true]
["-f" "--file FILE" "file doc"]
["-d" "--dir DIR" "dir doc"]]]
[(cli/parse-opts ["-a"] opts)
(cli/parse-opts ["-f x" "-d y" "-a"] opts)])
=>
[{:options {},
:arguments [],
:summary " -a something\n -f, --file FILE file doc\n -d, --dir DIR dir doc",
:errors ["Failed to validate \"-a \": Missing required -f and -d options"]}
{:options {:file " x", :dir " y", :a true},
:arguments [],
:summary " -a something\n -f, --file FILE file doc\n -d, --dir DIR dir doc",
:errors nil}]