package pflag
import "fmt"
type notExistErrorMessageType int
const (
flagNotExistMessage notExistErrorMessageType = iota
flagNoSuchFlagMessage
flagUnknownFlagMessage
flagUnknownShorthandFlagMessage
)
type NotExistError struct {
name string
specifiedShorthands string
messageType notExistErrorMessageType
}
func (e *NotExistError ) Error () string {
switch e .messageType {
case flagNotExistMessage :
return fmt .Sprintf ("flag %q does not exist" , e .name )
case flagNoSuchFlagMessage :
return fmt .Sprintf ("no such flag -%v" , e .name )
case flagUnknownFlagMessage :
return fmt .Sprintf ("unknown flag: --%s" , e .name )
case flagUnknownShorthandFlagMessage :
c := rune (e .name [0 ])
return fmt .Sprintf ("unknown shorthand flag: %q in -%s" , c , e .specifiedShorthands )
}
panic (fmt .Errorf ("unknown flagNotExistErrorMessageType: %v" , e .messageType ))
}
func (e *NotExistError ) GetSpecifiedName () string {
return e .name
}
func (e *NotExistError ) GetSpecifiedShortnames () string {
return e .specifiedShorthands
}
type ValueRequiredError struct {
flag *Flag
specifiedName string
specifiedShorthands string
}
func (e *ValueRequiredError ) Error () string {
if len (e .specifiedShorthands ) > 0 {
c := rune (e .specifiedName [0 ])
return fmt .Sprintf ("flag needs an argument: %q in -%s" , c , e .specifiedShorthands )
}
return fmt .Sprintf ("flag needs an argument: --%s" , e .specifiedName )
}
func (e *ValueRequiredError ) GetFlag () *Flag {
return e .flag
}
func (e *ValueRequiredError ) GetSpecifiedName () string {
return e .specifiedName
}
func (e *ValueRequiredError ) GetSpecifiedShortnames () string {
return e .specifiedShorthands
}
type InvalidValueError struct {
flag *Flag
value string
cause error
}
func (e *InvalidValueError ) Error () string {
flag := e .flag
var flagName string
if flag .Shorthand != "" && flag .ShorthandDeprecated == "" {
flagName = fmt .Sprintf ("-%s, --%s" , flag .Shorthand , flag .Name )
} else {
flagName = fmt .Sprintf ("--%s" , flag .Name )
}
return fmt .Sprintf ("invalid argument %q for %q flag: %v" , e .value , flagName , e .cause )
}
func (e *InvalidValueError ) Unwrap () error {
return e .cause
}
func (e *InvalidValueError ) GetFlag () *Flag {
return e .flag
}
func (e *InvalidValueError ) GetValue () string {
return e .value
}
type InvalidSyntaxError struct {
specifiedFlag string
}
func (e *InvalidSyntaxError ) Error () string {
return fmt .Sprintf ("bad flag syntax: %s" , e .specifiedFlag )
}
func (e *InvalidSyntaxError ) GetSpecifiedFlag () string {
return e .specifiedFlag
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .