Welcome! Please see the About page for a little more info on how this works.

+2 votes
in tools.cli by
recategorized by

I would like to have a --diff flag which defaults to origin/HEAD but allow pass a different rev in the arg, like --diff origin/bar.

Context: https://clojurians.slack.com/archives/C03S1KBA2/p1745859358672599

1 Answer

0 votes
by

The closest you can get is this:

clojure.tools.cli=> (parse-opts ["--diff="] [[nil "--diff NAME" "Diff" :parse-fn #(or (not-empty %) "foo")]])
{:options {:diff "foo"}, :arguments [], :summary "      --diff NAME  Diff", :errors nil}
clojure.tools.cli=> (parse-opts ["--diff=bar"] [[nil "--diff NAME" "Diff" :parse-fn #(or (not-empty %) "foo")]])
{:options {:diff "bar"}, :arguments [], :summary "      --diff NAME  Diff", :errors nil}

clojure.tools.cli=>

As discussed on Slack, there are reasonable cases for a value-bearing option to want to accept a string that starts with -- or just - (consider = to be optional here):

meta-command --option-to-use=--cabbage... \
--divider=--sep-- \
--value=-1
...