Exemple #1
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
}
Exemple #2
0
// 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
}
Exemple #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))
}