Files
kong/error.go
T
hasheddan a062611ecf Do not run parent node on missing child err with usageOnMissing option
Refactors usageOnMissing option to not run parent commands after
printing usage when a child node is missing.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-20 09:44:46 +11:00

44 lines
877 B
Go

package kong
import (
"fmt"
"strings"
)
// ParseError is the error type returned by Kong.Parse().
//
// It contains the parse Context that triggered the error.
type ParseError struct {
error
Context *Context
}
// Cause returns the original cause of the error.
func (p *ParseError) Cause() error { return p.error }
type missingChildError struct {
missing []string
}
func (m *missingChildError) Error() string {
if len(m.missing) > 5 {
m.missing = append(m.missing[:5], "...")
}
if len(m.missing) == 1 {
return fmt.Sprintf("expected %s", m.missing[0])
}
return fmt.Sprintf("expected one of %s", strings.Join(m.missing, ", "))
}
func newMissingChildError(missing []string) *missingChildError {
return &missingChildError{missing}
}
func isMissingChildError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*missingChildError)
return ok
}