feat(completion): complete enum flag values from schema - #425
Closed
levontumanyan wants to merge 1 commit into
Closed
feat(completion): complete enum flag values from schema#425levontumanyan wants to merge 1 commit into
levontumanyan wants to merge 1 commit into
Conversation
Extends the completion engine to offer valid enum values as tab candidates when the user is typing a value for an enum-typed flag (e.g. elastic stack es cat nodes --h <TAB>). How it works: - extractSchemaArgs() now extracts enumValues from z.enum (and union(z.enum, z.string)) fields via a new extractEnumValues() helper. - defineCommand() attaches a non-enumerable _enumCompleters map to the Commander command for each flag that has enumValues. - enumerate() falls back to _enumCompleters when the global registry has no completer for the previous flag token. Both the --flag value and --flag=partial forms are handled. Since enum values come from the generated Zod schemas, all cat API column flags (--h, --s where typed as enum) and any other enum-typed flags across the codebase get completions for free without any manual registration.
Contributor
Author
|
Closing — not needed. The flag value completion is out of scope for now; the original ask was positional (context name) completion only (PR #424). |
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.
Summary
Extends tab completion to offer valid enum values when typing a flag value — e.g.
elastic stack es cat nodes --h <TAB>now shows all available cat node column names.Approach
extractSchemaArgs()inschema-args.tsnow calls a newextractEnumValues()helper that walksz.enum,union(z.enum, z.string),optional, andlazywrappers to pull out enum values. These are stored asenumValues?: readonly string[]onSchemaArgDefinition.defineCommand()infactory.tsattaches a non-enumerable_enumCompleters: Map<string, () => string[]>to each Commander command object for every enum-typed flag.enumerate()checks_enumCompleterson the current command as a fallback when the global registry has no completer for the previous flag. Both--flag <TAB>and--flag=partial<TAB>forms are handled.Since enum values come directly from the generated Zod schemas (e.g.
CatCatNodeColumn), all cat API column flags and any other enum-typed flags across the codebase get completions automatically with no manual registration needed.Test plan
extractSchemaArgs -- enumValuessuite (5 new tests): plain enum, optional wrapper,union(enum, string)pattern, non-enum fieldsenumerate -- command-level enum completerssuite (4 new tests): basic invocation, prefix-filter,--flag=partialform, registry prioritynpm test— 1472/1472 passelastic stack es cat nodes --h <TAB>lists all cat node column names🤖 Generated with Claude Code