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
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
.