예제 #1
0
파일: as.go 프로젝트: DaveBlooman/slingshot
// AsBool tries to convert any of related aliases to bool
func (am ArgMap) AsBool(aliases ...string) bool {
	for _, key := range aliases {
		b, err := to.Bool(am[key])
		if err == nil {
			return b
		}
	}
	return false
}
예제 #2
0
// MayBool tries to convert any of related aliases to bool
func (am ArgMap) MayBool(defaultValue bool, aliases ...string) bool {
	for _, key := range aliases {
		b, err := to.Bool(am[key])
		if err == nil {
			return b
		}
	}
	return defaultValue
}
예제 #3
0
// MustBool tries to convert any of related aliases to bool. If no keys
// it panics.
func (am ArgMap) MustBool(aliases ...string) bool {
	for _, key := range aliases {
		if am[key] == nil {
			continue
		}

		b, err := to.Bool(am[key])
		if err != nil {
			panic(err)
		}
		return b
	}
	panic(fmt.Sprintf("None of these bool flags were found: %v", aliases))
}