Skip to content

feat(completion): complete enum flag values from schema - #425

Closed
levontumanyan wants to merge 1 commit into
elastic:mainfrom
levontumanyan:feat/enum-flag-completion
Closed

feat(completion): complete enum flag values from schema#425
levontumanyan wants to merge 1 commit into
elastic:mainfrom
levontumanyan:feat/enum-flag-completion

Conversation

@levontumanyan

Copy link
Copy Markdown
Contributor

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() in schema-args.ts now calls a new extractEnumValues() helper that walks z.enum, union(z.enum, z.string), optional, and lazy wrappers to pull out enum values. These are stored as enumValues?: readonly string[] on SchemaArgDefinition.
  • defineCommand() in factory.ts attaches a non-enumerable _enumCompleters: Map<string, () => string[]> to each Commander command object for every enum-typed flag.
  • enumerate() checks _enumCompleters on 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 -- enumValues suite (5 new tests): plain enum, optional wrapper, union(enum, string) pattern, non-enum fields
  • enumerate -- command-level enum completers suite (4 new tests): basic invocation, prefix-filter, --flag=partial form, registry priority
  • npm test — 1472/1472 pass
  • Manual: elastic stack es cat nodes --h <TAB> lists all cat node column names

🤖 Generated with Claude Code

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.
@levontumanyan

Copy link
Copy Markdown
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).

@levontumanyan
levontumanyan deleted the feat/enum-flag-completion branch June 18, 2026 08:32
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