A production-ready fork of Cobra Prompt that turns any Cobra CLI into a rich interactive shell with syntax highlighting, fuzzy completions, and proper shell semantics.
Built on elk-language/go-prompt, an actively maintained fork of go-prompt with critical bug fixes (Ctrl+C handling, terminal restoration, grapheme support).
The original cobra-prompt is unmaintained and has several critical bugs. Comptplus fixes all of them and adds features needed for production CLIs:
- Syntax highlighting: commands, flags, values, and errors are colorized as you type via a cobra-aware lexer
- Fuzzy completions: type
dplto matchdeploy, powered by go-prompt's fuzzy filter - Flag value completions: auto-complete flag values with caching and optional async (non-blocking) fetching
- Shell-aware parsing: quoted arguments (
--name "John Oliver") work correctly via go-shellquote - Proper cobra integration: uses
SetArgs()instead ofos.Args, passes resolved*cobra.Commandto callbacks - Graceful error handling: errors print and return to the prompt instead of calling
os.Exit(1) - Hooks and customization: pre/post execution hooks, custom flag reset logic, dynamic prefix, key bindings, and more
See the CHANGELOG for the full version history.
go get github.com/ionoscloudsdk/comptplus
package main
import (
"github.com/elk-language/go-prompt"
"github.com/ionoscloudsdk/comptplus"
)
func main() {
lexer := comptplus.NewCobraLexer(rootCmd)
cp := &comptplus.CobraPrompt{
RootCmd: rootCmd,
AddDefaultExitCommand: true,
FuzzyFilter: true,
GoPromptOptions: []prompt.Option{
prompt.WithPrefix("> "),
prompt.WithLexer(lexer),
},
}
cp.Run()
}go run ./_example
