Hi everyone, first time poster. I'm trying to use tools.cli from within a babashka script. So I'm not sure if my question should be oriented there or here but here it goes
Does anyone know how to enforce required options (ie. not missing) with tools.cli?
I've tried `:validate` and `:validate-fn` but they don't seem to be invoked for the value specified by the `:default` key (which as was suggested was ::missing
and the :validate
fn was :validate [(fn [x] (println "XXXXX:" x) (not= ::missing)) "Missing required option: --gitlab-token"]
@nicolas.estrada938 You could just do (assert (:required (:options parsed)) "required is required")
Should I do this after I invoke parse-opts
or in a :validate
key?
after
oh ok... that's all I needed to know 😉 Thanks! I do feel that tools.cli could benefit with a :mandatory
flag the way https://github.com/grammarly/omniconf does (too bad it doesn't work with babashka 😅 )
I think required options are contextual so it depends on how you invoked the tool. E.g. tool --help
doesn't require any other options, but tool --foo
might
Where does omniconf fail? We could look to make it work with bb if it's within reasonable distance. Let's talk in #babashka
Of course they are contextual, but if tools.cli performs validation I believe checking for existance falls into that category
Perhaps #clojure is the best channel to discuss new features for tools.cli.