go-getoptions v0.23.0 Release Notes
Release Date: 2020-10-21 // over 4 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
andFloat64VarOptional
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
andopt.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
andNBoolVar
.
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 usingopt.Bool
andopt.BoolVar
.
๐ Previously onlyopt.String
andopt.StringVar
were supported.When using
opt.GetEnv
withopt.Bool
oropt.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 commandopt.Dispatch
now returns an error of typegetoptions.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
orprogram list -?
prints the help for thelist
command as well as callingprogram help list
.