Documentation ¶
Overview ¶
Package komplete is a package for generating completions for Kong CLIs.
To use it, build a Kong parser from your CLI grammar, and then call Run with it to run the completion logic. This will automatically determine if the CLI is being invoked as a completion script or as a regular command.
parser, err := kong.New(cli) // ... komplete.Run(parser)
Command is provided as a convenient subcommand for generating completion scripts for various shells.
Custom logic to predict values for flags and arguments can be provided through WithPredictor. Install a predictor with a name, and refer to it in your CLI grammar with the `predictor:"name"` tag.
type CLI struct { Name string `help:"Name of the branch" predictor:"branches"` // ... } // ... komplete.Run(parser, komplete.WithPredictor("branches", branchesPredictor), // ... )
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Args ¶
type Args struct { // Completed is a list of arguments that have already been completed, // preceding the argument currently being typed. Completed []string // Last is the typed portion of the current argument. // Predictions will typically be matched against this. Last string }
Args holds the command line completion arguments.
type Command ¶
type Command struct {
Shell string `enum:"bash,zsh,fish," arg:"" default:"" optional:"" help:"Shell to generate completions for."`
}
Command is the command to run to generate the completion script. It is intended to be used as a subcommand of the main CLI.
type Option ¶
type Option func(*options)
Option customizes completion logic.
func WithPredictor ¶
WithPredictor adds a named predictor to the completion logic.
Flags and arguments can request a predictor for their values by adding a `predictor:"name"` tag to the field.
type CLI struct { Name string `help:"Name of the branch" predictor:"branches"` // ... } komplete.Run(parser, komplete.WithPredictor("branches", branchesPredictor), )
func WithTransformCompleted ¶
WithTransformCompleted allows modifying the list of completed arguments, allowing replication of any os.Args transformations.
type PredictFunc ¶
PredictFunc is a function that predicts completions for a set of arguments.
func (PredictFunc) Predict ¶
func (f PredictFunc) Predict(cargs Args) []string
Predict calls the function to predict completions.