Fork me on GitHub
Nicolas Estrada13:05:54

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

šŸ‘‹ 3
Nicolas Estrada13:05:05

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

Nicolas Estrada13:05:43

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

Nicolas Estrada13:05:38

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

Nicolas Estrada13:05:46

oh ok... that's all I needed to know šŸ˜‰ Thanks! I do feel that tools.cli could benefit with a :mandatory flag the way 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

āœ… 3
Nicolas Estrada13:05:02

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.