feat(spec): better suggestion with cobra's cli __complete subcmd (#40)

Introduces dynamic completion inference for Cobra-based CLIs using the
hidden `__complete` subcommand. Iris can now automatically suggest
subcommands and flags for commands without hand-written specs.

Completions are structured, cached by binary modification time
(`mtime`), and safely isolated from hand-written specs.

Try testing with un-specced commands:
- `gh repo ` (suggests `clone`, `fork`, `sync`...)
- `kubectl get ` (suggests `pods`, `nodes`, `configmaps`...)
- `golangci-lint ` (suggests `run`, `fmt`, `linters`...)
This commit is contained in:
VERSE
2026-07-26 19:44:42 +07:00
committed by GitHub
parent 6ffb9f83f2
commit c4e9bcdd88
3 changed files with 305 additions and 0 deletions
+8
View File
@@ -106,6 +106,14 @@ func Lookup(input string) []Suggestion {
spec, exists := Registry[rootCmdName]
logger.Debugf("core lookup tokens: %v, registry exists: %v", tokens, exists)
if !exists {
partial := tokens[len(tokens)-1]
args := tokens[1:]
if len(args) > 0 && args[len(args)-1] == partial {
args = args[:len(args)-1]
}
if cobSugg := QueryCobraComplete(rootCmdName, args, partial); len(cobSugg) > 0 {
return cobSugg
}
return nil
}