Ejemplo n.º 1
0
// AsInt should get value from path or return val.
func (am ArgMap) AsInt(aliases ...string) int {
	for _, key := range aliases {
		i, err := to.Int64(am[key])
		if err == nil {
			return int(i)
		}
	}
	return 0
}
Ejemplo n.º 2
0
// MayInt should get value from path or return val.
func (am ArgMap) MayInt(defaultValue int, aliases ...string) int {
	for _, key := range aliases {
		i, err := to.Int64(am[key])
		if err == nil {
			return int(i)
		}
	}
	return defaultValue
}
Ejemplo n.º 3
0
// MustInt should get value from path or return val.
func (am ArgMap) MustInt(aliases ...string) int {
	for _, key := range aliases {
		if am[key] == nil {
			continue
		}

		i64, err := to.Int64(am[key])
		if err != nil {
			continue
		}
		return int(i64)
	}
	panic(fmt.Sprintf("None of these int flags were found or convertable to int: %v", aliases))
}