cmpcobra

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCmd

func RegisterCmd(cmd *cobra.Command, predictor predict.Predictor)

RegisterCmd for custom completion logic

The default completion resolves sub-command names (if any), valid args, or filenames. This can override that with something more fitting.

Ideally this would be scoped to a single Completer, but it's inconvenient for all command "factories" to share that value around. The registered values are unique pointers so overwriting won't happen.

func RegisterFlag

func RegisterFlag(cmd *cobra.Command, name string, predictor predict.Predictor)

RegisterFlag for custom completion logic

The default completion type resolves filenames. This can override that with something more fitting.

Ideally this would be scoped to a single Completer, but it's inconvenient for all command "factories" to share that value around. The registered values are unique pointers so overwriting won't happen.

Types

type Completer

type Completer struct {
	// contains filtered or unexported fields
}

Completer is aware of Cobra CLI semantics, and can generate a tab completion skeleton for them.

func New

func New(root *cobra.Command, opts ...Option) *Completer

func (*Completer) Command

func (c *Completer) Command() command.Command

Command traversed the *cobra.Command to create a completion skeleton, substituting registered predictors in their appropriate places

func (*Completer) Parse

func (c *Completer) Parse(args []string) any

Parse the arguments and return the most relevant *cobra.Command for predictors to inspect

Predictors can run cmd.Root() if they want access to other things.

type Option

type Option func(*options)

func ShowHiddenFlags

func ShowHiddenFlags(show bool) Option

ShowHiddenFlags controls whether flags explicitly marked as hidden should appear in suggestions

Jump to

Keyboard shortcuts

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