suggest

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: ? 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

Index

Constants

View Source
const MaxDistance = 3

MaxDistance is the maximum Levenshtein distance for a suggestion to be considered

Variables

This section is empty.

Functions

func FormatSuggestion

func FormatSuggestion(itemType, unknown string, suggestion *Suggestion) string

FormatSuggestion formats a single suggestion message

func FormatSuggestions

func FormatSuggestions(itemType, unknown string, suggestions []Suggestion) string

FormatSuggestions formats multiple suggestions

func LevenshteinDistance

func LevenshteinDistance(a, b string) int

LevenshteinDistance calculates the edit distance between two strings

func ParseCommandError

func ParseCommandError(errMsg string, availableCommands []string) error

ParseCommandError extracts the command name from a Cobra command error and returns an enhanced error with suggestions

func ParseCommandErrorWithHint

func ParseCommandErrorWithHint(errMsg string, availableCommands []string, usageHint string) error

ParseCommandErrorWithHint is like ParseCommandError but includes a usage hint

func ParseFlagError

func ParseFlagError(errMsg string, availableFlags []string) error

ParseFlagError extracts the flag name from a Cobra flag error message and returns an enhanced error with suggestions

func UnknownCommandName

func UnknownCommandName(errMsg string) string

UnknownCommandName returns the command name a Cobra command error names, or "".

func UnknownFlagName

func UnknownFlagName(errMsg string) string

UnknownFlagName returns the flag name a Cobra flag error names, or "".

Types

type CommandError

type CommandError struct {
	Command     string
	Message     string
	Suggestion  *Suggestion
	Suggestions []Suggestion
	UsageHint   string
	// Runnable holds complete command lines that do what the caller most
	// likely meant. It does not change Error(); an agent envelope offers these
	// in place of the did-you-mean prose, so a caller can run one as-is.
	Runnable []string
}

CommandError represents an error with command/subcommand that includes suggestions

func (*CommandError) Error

func (e *CommandError) Error() string

type FlagError

type FlagError struct {
	Flag       string
	Message    string
	Suggestion *Suggestion
}

FlagError represents an error with flag parsing that includes suggestions

func (*FlagError) Error

func (e *FlagError) Error() string

type Suggestion

type Suggestion struct {
	Value    string
	Distance int
}

Suggestion represents a suggested correction with its distance score

func FindClosest

func FindClosest(input string, candidates []string) *Suggestion

FindClosest finds the closest match from a list of candidates

func FindClosestN

func FindClosestN(input string, candidates []string, n int) []Suggestion

FindClosestN finds the N closest matches from a list of candidates

Jump to

Keyboard shortcuts

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