Skip to content

Make subcommand placeholder customizable, add shell auto-completion support - #11

Merged
amterp merged 2 commits into
mainfrom
ra2
Feb 15, 2026
Merged

amterp merged 2 commits into
mainfrom
ra2

Conversation

@amterp

@amterp amterp commented Feb 15, 2026

Copy link
Copy Markdown
Owner

See individual commits for details.

Add SubcommandPlaceholder field to UsageHeaders so
consumers can customize the synopsis text (e.g. show
"[command]" instead of "[subcommand]"). Defaults to
"subcommand" to preserve existing behavior.
Adds opt-in Tab-completion for any Ra-based CLI. When
enabled, Ra recognizes a hidden __complete subcommand
that the shell shim invokes on Tab press. The Go-side
algorithm determines context (subcommand, flag name,
flag value, positional) and returns candidates with a
directive bitmask.

Completion is context-aware:
- Walks the subcommand tree (handles interleaved flags)
- Tracks used flags to avoid re-offering non-slice flags
- Respects -- separator (positional-only after it)
- Handles variadic positionals (keeps completing them)
- Supports --flag=val and -f=val inline syntax
- Hides hidden and positional-only flags
- Completes enum values for constrained StringFlags
- Supports custom CompletionFunc on all value-taking
  flag types for dynamic completions (e.g. git branches)

Includes bash and zsh shim generators via
GenBashCompletion/GenZshCompletion. Fish/PowerShell
can be added later following the same pattern.

Follows the existing sentinel error pattern
(HelpInvokedErr, DumpInvokedErr) so ParseOrExit exits
cleanly and ParseOrError returns CompletionInvokedErr.
@amterp
amterp merged commit 1916787 into main Feb 15, 2026
@amterp
amterp deleted the ra2 branch February 15, 2026 20:11
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