tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
Nicolas Estrada 2021-05-31T13:27:54.065900Z

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

👋 1
Nicolas Estrada 2021-05-31T13:28:05.066100Z

Does anyone know how to enforce required options (ie. not missing) with tools.cli?

Nicolas Estrada 2021-05-31T13:29:43.066500Z

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"]

borkdude 2021-05-31T13:30:06.067100Z

@nicolas.estrada938 You could just do (assert (:required (:options parsed)) "required is required")

Nicolas Estrada 2021-05-31T13:31:38.067200Z

Should I do this after I invoke parse-opts or in a :validate key?

borkdude 2021-05-31T13:31:53.067400Z

after

Nicolas Estrada 2021-05-31T13:33:46.067600Z

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 😅 )

borkdude 2021-05-31T13:33:53.067900Z

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

borkdude 2021-05-31T13:35:38.068100Z

Where does omniconf fail? We could look to make it work with bb if it's within reasonable distance. Let's talk in #babashka

✅ 1
Nicolas Estrada 2021-05-31T13:36:02.068300Z

Of course they are contextual, but if tools.cli performs validation I believe checking for existance falls into that category

borkdude 2021-05-31T13:36:50.068600Z

Perhaps #clojure is the best channel to discuss new features for tools.cli.