MCPcopy
hub / github.com/charmbracelet/fang / isUsageError

Function isUsageError

help.go:136–150  ·  view source on GitHub ↗

XXX: this is a hack to detect usage errors. See: https://github.com/spf13/cobra/pull/2266

(err error)

Source from the content-addressed store, hash-verified

134// XXX: this is a hack to detect usage errors.
135// See: https://github.com/spf13/cobra/pull/2266
136func isUsageError(err error) bool {
137 s := err.Error()
138 for _, prefix := range []string{
139 "flag needs an argument:",
140 "unknown flag:",
141 "unknown shorthand flag:",
142 "unknown command",
143 "invalid argument",
144 } {
145 if strings.HasPrefix(s, prefix) {
146 return true
147 }
148 }
149 return false
150}
151
152func writeLongShort(w *colorprofile.Writer, styles Styles, longShort string) {
153 if longShort == "" {

Callers 2

DefaultErrorHandlerFunction · 0.85
TestIsUsageErrorFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsUsageErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…