CLI-style subcommand dispatch for a consolidated tool.
make-handler turns a handler tree into a single fn dispatching on the
:command parameter, supporting n-depth paths ("status list") alongside
single-word commands.
CLI-style subcommand dispatch for a consolidated tool.
`make-handler` turns a handler tree into a single fn dispatching on the
:command parameter, supporting n-depth paths ("status list") alongside
single-word commands.(make-handler handlers)(make-handler handlers {:keys [coerce-schema coerce-fn error-fn]})A handler fn dispatching on the :command parameter of its argument map.
HANDLERS maps keyword segments to handler fns or to nested trees; a tree may carry :_handler as its default. "help" at the root renders the command list.
OPTS:
:coerce-schema {field [type-spec]} — string params are coerced to the
declared types before dispatch
:coerce-fn (fn [schema params] -> Result) performing that coercion.
REQUIRED whenever :coerce-schema is given.
hive-dsl.coerce/coerce-map is the usual argument.
:error-fn builds an error result; defaults to
hive-addon.cli.response/error, and a host may pass its
own enriched builder
Coercion arrives as an INJECTED FN rather than being resolved here. This
namespace previously did #?(:clj (requiring-resolve 'hive-dsl.coerce/...)),
which is wrong twice over: :clj does not select the JVM (cljw presents it,
cljrs presents :rust, so on cljrs the form vanished and coercion silently
became a no-op), and hive-dsl.coerce pulls in clojure.data.json — a
dependency this leaf library declines to acquire on every consumer's behalf
for a feature most of them do not use.
Declaring :coerce-schema without :coerce-fn THROWS rather than dispatching uncoerced. Silently handing a handler the raw string params it asked to have coerced is the failure this refusal exists to prevent, and wiring-time is where it can still be fixed cheaply.
A handler fn dispatching on the :command parameter of its argument map.
HANDLERS maps keyword segments to handler fns or to nested trees; a tree
may carry :_handler as its default. "help" at the root renders the
command list.
OPTS:
:coerce-schema {field [type-spec]} — string params are coerced to the
declared types before dispatch
:coerce-fn (fn [schema params] -> Result) performing that coercion.
REQUIRED whenever :coerce-schema is given.
`hive-dsl.coerce/coerce-map` is the usual argument.
:error-fn builds an error result; defaults to
`hive-addon.cli.response/error`, and a host may pass its
own enriched builder
Coercion arrives as an INJECTED FN rather than being resolved here. This
namespace previously did `#?(:clj (requiring-resolve 'hive-dsl.coerce/...))`,
which is wrong twice over: `:clj` does not select the JVM (cljw presents it,
cljrs presents :rust, so on cljrs the form vanished and coercion silently
became a no-op), and `hive-dsl.coerce` pulls in clojure.data.json — a
dependency this leaf library declines to acquire on every consumer's behalf
for a feature most of them do not use.
Declaring :coerce-schema without :coerce-fn THROWS rather than dispatching
uncoerced. Silently handing a handler the raw string params it asked to have
coerced is the failure this refusal exists to prevent, and wiring-time is
where it can still be fixed cheaply.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |