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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user