go-getoptions v0.23.0 Release Notes

Release Date: 2020-10-21 // over 3 years ago
  • ๐Ÿš€ As the releases before, this release has 100% test coverage.
    โœ… Tested with Go 1.14 and Go 1.15.

    ๐Ÿ”‹ Feature Updates

    Introduce Float64Optional and Float64VarOptional to have complete method parity for String, Int and Float64 types.

    ๐Ÿ‘Œ Support multi-line command descriptions.

    โž• Add GetEnv support for missing single option types:

    • Int, IntVar, IntOptional, IntVarOptional
    • StringOptional, StringVarOptional
    • Float64, Float64Var, Float64Optional, Float64VarOptional

    0๏ธโƒฃ NOTE: For numeric values, opt.Int and opt.Float64 and their derivatives, environment variable string conversion errors are ignored and the default value is assigned.


Previous changes from v0.22.0

  • ๐Ÿš€ As the releases before, this release has 100% test coverage.
    โœ… Tested with Go 1.14 and Go 1.15.

    ๐Ÿ› Bug fix

    ๐Ÿ›  Fix completion issues where a completion that works when starting to complete from scratch fails when some args are deleted.

    ๐Ÿ›  Fixed by changing the exit status when generating completions from 1 to 124.
    Exit 124 means programmable completion restarts from the beginning, with an attempt to find a new compspec for that command.

    ๐Ÿ”‹ Feature Removal

    Removing negatable flags NBool and NBoolVar.
    A feature that adds a bunch of complexity for very little value and prevents reading environment variables into booleans.

    ๐Ÿ†• New Features

    ๐Ÿ‘ opt.GetEnv Is now supported when using opt.Bool and opt.BoolVar.
    ๐Ÿ‘ Previously only opt.String and opt.StringVar were supported.

    When using opt.GetEnv with opt.Bool or opt.BoolVar, only the words "true" or "false" are valid.
    They can be provided in any casing, for example: "true", "True" or "TRUE".

    opt.Dispatch now automatically handles the help flag.
    The help flag needs to be defined at the top level.
    When the help flag is called and handled by a command opt.Dispatch now returns an error of type getoptions.ErrorHelpCalled.

    For example:

    func main() { os.Exit(program()) }func program() int { opt := getoptions.New() opt.Bool("help", false, opt.Alias("?")) // Define the help flag as "--help" with alias "-?"list := opt.NewCommand("list", "list stuff").SetCommandFn(listRun) list.Bool("list-opt", false) opt.HelpCommand("") remaining, err := opt.Parse(os.Args[1:]) if err != nil { fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) os.Exit(1) } ctx, cancel, done := opt.InterruptContext() defer func() { cancel(); \<-done }() err = opt.Dispatch(ctx, "help", remaining) // Use the same help flag "help".if err != nil { if errors.Is(err, getoptions.ErrorHelpCalled) { return 1 } fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) return 1 } return 0}
    

    ๐Ÿ–จ Now, calling program list --help or program list -? prints the help for the list command as well as calling program help list.