complete

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package complete builds shell completion functions from local data: enum flags whose help text and completions come from one list, file and directory filters, and dynamic lists with a timeout.

Index

Constants

View Source
const Timeout = time.Second

Timeout is how long a dynamic completion may take before it gives up.

Variables

This section is empty.

Functions

func Assign

func Assign(cs []Choice) cobra.CompletionFunc

Assign returns a completion function for key=path values such as --out json=report.json. It offers each value of cs followed by "=", and file names once the key is typed.

func Dirs

func Dirs() cobra.CompletionFunc

Dirs returns a completion function for directory names.

func Dynamic

func Dynamic(timeout time.Duration, src Source) cobra.CompletionFunc

Dynamic returns a completion function that offers what src lists, filtered by prefix. When src fails or takes longer than timeout, it offers nothing and returns ShellCompDirectiveError.

func DynamicList

func DynamicList(timeout time.Duration, src Source) cobra.CompletionFunc

DynamicList is Dynamic for a comma-separated list, completing the last element like List.

func Enum

func Enum(cs []Choice) cobra.CompletionFunc

Enum returns a completion function that offers cs with descriptions and no file names.

func Files

func Files(exts ...string) cobra.CompletionFunc

Files returns a completion function for file names with one of exts (without the dot), or any file when exts is empty. fish and PowerShell ignore the filter and list every file.

func IsRequest

func IsRequest(cmd *cobra.Command) bool

IsRequest reports whether cmd answers a completion request (cobra's __complete or carapace's _carapace) instead of running a command.

func Join

func Join(cs []Choice) string

Join lists the values of cs for help text, as in "a, b or c".

func List

func List(cs []Choice) cobra.CompletionFunc

List returns a completion function for a comma-separated list of cs values. It completes the last element, keeps the ones before it and leaves out values already in the list.

func NoFiles

NoFiles is a completion function for free-form values: it offers nothing, not even file names.

func Usage

func Usage(text string, cs []Choice) string

Usage returns text with every "{values}" replaced by Join of cs.

func Values

func Values(cs []Choice) []string

Values returns the values of cs in order.

func WithoutDynamic added in v0.6.0

func WithoutDynamic(ctx context.Context) context.Context

WithoutDynamic returns a context in which Dynamic and DynamicList offer nothing, so a caller can read the fixed choices of every flag without touching local files.

Types

type Choice

type Choice struct {
	Value string
	Desc  string
}

Choice is one allowed value of an enum flag.

func StaticValues added in v0.6.0

func StaticValues(cmd *cobra.Command, f cobra.CompletionFunc) []Choice

StaticValues returns the fixed values that f offers for an empty word: the choices of an enum or list flag, or the keys of an assign flag. It returns nil for files, directories, free-form and dynamic flags.

type ConfigTools

type ConfigTools func(ctx context.Context, cmd *cobra.Command) (registry.ConfigLayer, error)

ConfigTools returns the tools and aliases of the user's config files.

type Source

type Source func(ctx context.Context, cmd *cobra.Command, toComplete string) ([]Choice, error)

Source lists choices from local data. cmd gives access to the flags parsed so far.

func Tools

func Tools(cfg ConfigTools) Source

Tools lists the tool names of the embedded relgap registry, the config and the embedded mise registry snapshot, with their repositories as descriptions. It never runs mise or calls GitHub.

Jump to

Keyboard shortcuts

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