komplete

package
v0.1.0-alpha1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

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

func Run

func Run(parser *kong.Kong, opts ...Option)

Run runs the CLI argument completer if the user has requested completions. Otherwise, this is a no-op.

Types

type Command

type Command struct {
	Shell string ` enum:"bash,zsh,fish" arg:"" required:"" 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.

func (*Command) Run

func (cmd *Command) Run(kctx *kong.Context) (err error)

Run runs the completion script generator. It will print the completion script to stdout and exit.

type Option

type Option func(*options)

Option customizes completion logic.

func WithPredictor

func WithPredictor(name string, predictor complete.Predictor) Option

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

func WithTransformCompleted(fn func([]string) []string) Option

WithTransformCompleted allows modifying the list of completed arguments, allowing replication of any os.Args transformations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL