Skip to content

Releases: pressly/cli

v0.7.0

14 May 20:52
d101639

Choose a tag to compare

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.EnumDefault constructor for enums with an initial default value
  • Cmd field on State exposing the terminal command selected during parsing
  • Summary field on Command for the short text shown in command lists
  • UsageErrorf for opt-in usage errors; Run prints command help to stderr before returning the
    underlying error

Changed

  • BREAKING: Replace Command.UsageFunc with Command.Help, which returns the full help string
    for a command
  • BREAKING: Replace Command.ShortHelp with Command.Summary for command lists and
    Command.Description for longer command help text
  • BREAKING: Rename FlagOption to FlagConfig and Command.FlagOptions to
    Command.FlagConfigs
  • Commands with subcommands and no Exec now report a usage error when no child command is
    selected, before enforcing required flags inherited by child commands

Removed

  • BREAKING: Remove ErrHelp; check errors.Is(err, flag.ErrHelp) when handling Parse
    directly
  • BREAKING: Remove DefaultUsage and the top-level Usage function from the public API

Full Changelog: v0.6.0...v0.7.0

v0.6.0

18 Feb 13:02
v0.6.0
b28286b

Choose a tag to compare

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")