Releases: pressly/cli
Releases · pressly/cli
v0.6.0
Added
New flagtype package with common flag.Value implementations for use with flag.FlagSet.Var.
The standard library's flag package only covers basic types (string, int, bool, etc.). For anything richer -- repeatable flags, enums, key-value pairs -- you're left writing boilerplate flag.Value implementations. The flagtype package provides ready-made types that integrate with cli.GetFlag for type-safe retrieval.
Available types: StringSlice, Enum, StringMap, URL, and Regexp.
Flags: cli.FlagsFunc(func(f *flag.FlagSet) {
f.Var(flagtype.StringSlice(), "tag", "add a tag (repeatable)")
f.Var(flagtype.Enum("json", "yaml", "table"), "format", "output format")
f.Var(flagtype.StringMap(), "label", "key=value pair (repeatable)")
f.Var(flagtype.URL(), "endpoint", "service endpoint URL")
f.Var(flagtype.Regexp(), "filter", "regex filter pattern")
})
// In Exec:
tags := cli.GetFlag[[]string](s, "tag")
format := cli.GetFlag[string](s, "format")
labels := cli.GetFlag[map[string]string](s, "label")
endpoint := cli.GetFlag[*url.URL](s, "endpoint")
filter := cli.GetFlag[*regexp.Regexp](s, "filter")