Documentation
¶
Index ¶
- Constants
- func FormatSuggestion(itemType, unknown string, suggestion *Suggestion) string
- func FormatSuggestions(itemType, unknown string, suggestions []Suggestion) string
- func LevenshteinDistance(a, b string) int
- func ParseCommandError(errMsg string, availableCommands []string) error
- func ParseCommandErrorWithHint(errMsg string, availableCommands []string, usageHint string) error
- func ParseFlagError(errMsg string, availableFlags []string) error
- func UnknownCommandName(errMsg string) string
- func UnknownFlagName(errMsg string) string
- type CommandError
- type FlagError
- type Suggestion
Constants ¶
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 ¶
LevenshteinDistance calculates the edit distance between two strings
func ParseCommandError ¶
ParseCommandError extracts the command name from a Cobra command error and returns an enhanced error with suggestions
func ParseCommandErrorWithHint ¶
ParseCommandErrorWithHint is like ParseCommandError but includes a usage hint
func ParseFlagError ¶
ParseFlagError extracts the flag name from a Cobra flag error message and returns an enhanced error with suggestions
func UnknownCommandName ¶
UnknownCommandName returns the command name a Cobra command error names, or "".
func UnknownFlagName ¶
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
type Suggestion ¶
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