v0.22.0: Breaking Change
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 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
or program list -?
prints the help for the list
command as well as calling program help list
.