Help us shape the future of Go! Take the 2026 Go Developer Survey

commandsuggest

package
v1.47.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package commandsuggest records commands explicitly authored by CLI presenters. It never discovers commands by inspecting arbitrary output.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("command selection canceled")

ErrCanceled means that the picker returned no selection.

Functions

func Configure

func Configure(root *cli.Command) func()

Configure enables the optional shell transport and returns its idempotent flush. The shell supplies an already-open private file, never a pathname to create.

func Invalidate

func Invalidate(command *cli.Command)

Invalidate discards this invocation's suggestions after a failed presentation. Already emitted links must never resolve through a partial command capture.

func OpenPickerInput

func OpenPickerInput(output *os.File) (*os.File, error)

OpenPickerInput owns a readable duplicate of the supplied physical terminal. Candidate stdin can be a pipe, and shell widgets may lack a controlling tty.

func Pick

func Pick(ctx context.Context, input, output *os.File, candidates []Candidate, title string, integration bool) (string, error)

Pick runs the shared local selector. It returns data and never executes it. Input and output belong to the foreground terminal, separate from data pipes.

func Record

func Record(command *cli.Command, text string) string

Record registers a command and adds an optional terminal insertion link.

func RecordFor

func RecordFor(command *cli.Command, shell, text string) string

RecordFor records a command only for the named shell integration.

func RecordLabel

func RecordLabel(command *cli.Command, label, target string) string

RecordLabel displays a label whose insertion target is an explicit command. Registration occurs when the presenter renders the label, never during setup.

func RecordTo

func RecordTo(command *cli.Command, output io.Writer, text string) string

RecordTo registers a command at its actual human-readable output destination.

func RenderText

func RenderText(text string, suggestions []string, render func(string) string) string

RenderText renders literal spans declared by the presenter. It does not discover suggestions in prose. Replacements use one pass, so nested commands and text returned by render cannot create new spans.

func SetRecorder

func SetRecorder(command *cli.Command, recorder Recorder)

SetRecorder attaches a recorder without replacing the command's output writer.

func WriteLine

func WriteLine(command *cli.Command, output io.Writer, text string) error

WriteLine displays one explicitly requested command. Failed writes invalidate capture, including when the optional link consumes more bytes.

Types

type Candidate

type Candidate struct {
	Command     string
	Description string
}

Candidate is a declared command, never an instruction to execute it.

func Catalog

func Catalog(root *cli.Command, invocation string, children func(*cli.Command) []*cli.Command, examples func(*cli.Command, string) []Candidate) []Candidate

Catalog derives discovery from the current command tree on every invocation. The callbacks reuse help's ordering and authored examples without rendering help.

func ReadCandidates

func ReadCandidates(input io.Reader) ([]Candidate, error)

ReadCandidates accepts the bounded, single-line suggestion transport only. Reject the whole input on malformed data; never silently select from a partial list.

func Search(candidates []Candidate, query string) []Candidate

Search returns declared candidates in the same order as the interactive picker.

type Recorder

type Recorder interface {
	Record(output io.Writer, shell, text string)
}

Recorder receives explicit suggestions and their human-readable destination. An empty shell means that the suggestion applies to any supported shell.

Jump to

Keyboard shortcuts

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