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

+1 vote
ago in tools.cli by

I frequently write a command that accepts options and in turn execute a shell command passing arguments through; I want to be able to specify additional arguments to that shell command.

In tools.cli, the :in-order key almost does what i want:

`
(require '[clojure.tools.cli :as cli])
=> nil
(def opts [["-d" "--debug"]])
=> #'net.lewisship.cli-tools-test/opts
(cli/parse-opts

["--foo"]
[]
:in-order true)

=> {:options {}, :arguments [], :summary "", :errors ["Unknown option: \"--foo\""]}
(cli/parse-opts

["xxx" "--foo"]
[]
:in-order true)

=> {:options {}, :arguments ["xxx" "--foo"], :summary "", :errors nil}
`

However, it will assume an undefined option is an error until the first non-option argument is consumed.

I would like a further option that is like :in-order but accepting of these unrecognized options. Maybe, :passthru-options would be a good name?

I can work on a patch if we have some consensus on direction.

1 Answer

+1 vote
ago by

Logged as https://clojure.atlassian.net/browse/TCLI-107 with a proposed syntax:

  • :subcommand :explicit will have the same meaning as :in-order true does today
  • :subcommand :implicit will have the behavior the OP wants here, i.e., an unknown option is treated as if there were an implicit subcommand present

Deprecate :in-order true (in favor of :subcommand :explicit).

...