Skip to content

Expose parse-opts*, coerce-opts, validate-opts, apply-defaults#149

Merged
borkdude merged 11 commits into
mainfrom
expose
May 23, 2026
Merged

Expose parse-opts*, coerce-opts, validate-opts, apply-defaults#149
borkdude merged 11 commits into
mainfrom
expose

Conversation

@borkdude
Copy link
Copy Markdown
Contributor

No description provided.

borkdude added 11 commits March 20, 2026 12:40
- Strip internal `::implicit-true-keys` and `::keys-order` from
  `parse-opts` result metadata.
- Track key parse order in `parse-opts*` meta; `coerce-opts` iterates
  by it so coerce errors fire in parse order, not map hash order.
- Document that `:exec-args` values bypass coercion.
- Tests: meta-not-leaked, coerce-error-order for >8 keys, pinning
  tests for `:bool` and coll-wrapped `:boolean`.
Decouples parse / coerce / validate / defaults so callers can interleave
external config (e.g. config files) into the pipeline:

  parse-opts* -> external merge -> apply-defaults -> coerce-opts -> validate-opts

- `parse-opts*` is now public: parses CLI args to a raw map with no
  coercion, no defaults, no validation. Useful for peek-style parsing
  and for callers that need to merge config from elsewhere before
  coercion.
- `apply-defaults` fills missing keys from spec `:default` entries
  (via `:exec-args`). Preserves metadata of input.
- `coerce-opts` now reads `::implicit-true-keys` and `::keys-order`
  from input metadata when not explicitly passed in opts, so callers
  don't need to thread them manually.

Tests added: parse-opts*, apply-defaults, full squint-style pipeline.
Previously the only way for a caller to detect 'user supplied --foo
without a value, coerce rejected the implicit true' was to pattern-
match on :value being the string "true" - fragile because the same
string from explicit '--foo true' would also match, and "true" was
a parser-internal stringification.

Surface :implicit-true true in error data when the failure originates
from an implicit-true coercion. throw-coerce already had the info as
an arg; just put it in ex-data and propagate through the catch in
coerce-opts.
# Conflicts:
#	CHANGELOG.md
#	test/babashka/cli_test.cljc
setup-clojure 13.x hits GH API to resolve 'latest'; with the implicit
token it currently fails 'Bad credentials' on Windows runners. Pin to
a specific bb version (avoids the API lookup) and pass the token
explicitly.
@borkdude borkdude merged commit cfe355b into main May 23, 2026
13 of 20 checks passed
@borkdude borkdude deleted the expose branch May 23, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant