refactor: improve z.enum support in CLI framework#1076
Merged
hsablonniere merged 6 commits intomasterfrom Apr 2, 2026
Merged
Conversation
b4f431b to
e561dbf
Compare
|
🔎 The preview has been automatically deleted. |
Several options and arguments use z.enum() schemas, but enum values are manually duplicated in descriptions and autocomplete arrays. To enable automatic extraction, a helper is needed that can unwrap Zod schema wrappers (default, optional, nullable, pipe) and retrieve the underlying enum values programmatically.
The command info model is the single source of truth consumed by help display, docs generation, and autocomplete. Exposing enumValues here makes them available to all consumers without each one needing to call getEnumValues() directly on the Zod schema.
Help output, reference docs, and LLM docs each manually formatted enum values differently. Now that enumValues is part of the command info model, all three consumers can render them consistently and automatically from the Zod schema definition.
Options and arguments using z.enum() had to manually specify a complete array with the same values. By falling back to getEnumValues() when no explicit complete is provided, autocomplete stays in sync with the schema automatically.
Enum values were listed both in the z.enum() schema and manually in description strings. Now that help, docs, and autocomplete extract them from the schema, keeping them in descriptions would result in duplication like "Output format (human, json) (human, json)".
The drain-type argument was validated with a manual if-check and had a manually specified complete array, both duplicating the list of valid types. Using z.enum() instead lets Zod handle validation with a clear error message, while help display and autocomplete are now derived automatically.
e561dbf to
fb1b8b7
Compare
pdesoyres-cc
approved these changes
Apr 2, 2026
Contributor
pdesoyres-cc
left a comment
There was a problem hiding this comment.
Perfect. Well done!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Enum values defined in
z.enum()schemas were manually duplicated in descriptions across 7 files, creating maintenance burden and fragility. When adding a new enum value, every copy had to be updated or things would silently diverge.Additionally, explicit autocomplete arrays and manual validation were duplicated for each enum, preventing a unified approach to displaying and validating enum choices.
Proposal
Add framework-level introspection for
z.enum()schemas:getEnumValues(schema)— unwrap Zod wrappers (default, optional, nullable, pipe) and extract enum valuesgetCommandInfo()— addenumValuesfield toOptionInfoandArgumentInfo--help, LLM docs, and markdown referencez.enum()get autocomplete for free viabin/clever.jsz.enum()instead of manual validation, leveraging the new frameworkThis replaces 7 manual enum value lists in descriptions with zero duplication, and provides better UX (help text, autocomplete) without extra code.
How to test