Releases: pressly/cli
v0.7.0
Docs: https://pressly.github.io/cli
See #19 for more context on the API changes in this release.
More breaking changes in one release than I'd prefer. Each one fixed something that had been bugging me, especially the usage and error composition. I expect the API to settle from here.
Added
flagtype.EnumDefaultconstructor for enums with an initial default valueCmdfield onStateexposing the terminal command selected during parsingSummaryfield onCommandfor the short text shown in command listsUsageErrorffor opt-in usage errors;Runprints command help to stderr before returning the
underlying error
Changed
- BREAKING: Replace
Command.UsageFuncwithCommand.Help, which returns the full help string
for a command - BREAKING: Replace
Command.ShortHelpwithCommand.Summaryfor command lists and
Command.Descriptionfor longer command help text - BREAKING: Rename
FlagOptiontoFlagConfigandCommand.FlagOptionsto
Command.FlagConfigs - Commands with subcommands and no
Execnow report a usage error when no child command is
selected, before enforcing required flags inherited by child commands
Removed
- BREAKING: Remove
ErrHelp; checkerrors.Is(err, flag.ErrHelp)when handlingParse
directly - BREAKING: Remove
DefaultUsageand the top-levelUsagefunction from the public API
Full Changelog: v0.6.0...v0.7.0
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")