Example #1
0
// MayString should get value from path or return val.
func (am ArgMap) MayString(defaultValue string, aliases ...string) string {
	if len(aliases) == 0 {
		panic("Alias key(s) required")
	}
	for _, key := range aliases {
		s := to.String(am[key])
		if len(s) > 0 {
			return s
		}
	}
	return defaultValue
}
Example #2
0
// AsString should get value from path or return val.
func (am ArgMap) AsString(aliases ...string) string {
	if len(aliases) == 0 {
		panic("Alias key(s) required")
	}
	for _, key := range aliases {
		s := to.String(am[key])
		if len(s) > 0 {
			return s
		}
	}
	return ""
}
Example #3
0
// MustString should get value from path or return val.
func (am ArgMap) MustString(aliases ...string) string {
	for _, key := range aliases {
		if am[key] == nil {
			continue
		}

		s := to.String(am[key])
		if s == "" {
			continue
		}
		return s
	}
	panic(fmt.Sprintf("None of these string flags were found: %v", aliases))
}