Changelog History
Page 1
-
v0.23.0 Changes
October 21, 2020๐ 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. -
v0.22.0 Changes
October 11, 2020๐ 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
. -
v0.21.0 Changes
August 15, 2020๐ As the releases before, this release has 100% test coverage.
โฌ๏ธ Drop support for Go versions before 1.14
โฌ๏ธ Dropping support for Go 1.10, 1.11, 1.12 and 1.13 to leverage new errors and testing features.
๐ท In particular The
errors.Is
anderrors.As
features greatly simplify error testing and handling and are used in the new DAG build system.๐ New Feature
๐ท Introduces a new Directed Acyclic Graph Build System.
๐ท The build system is a separate import package:
import "github.com/DavidGamba/go-getoptions/dag"
๐ Documentation can be found in its own README.
-
v0.20.2 Changes
July 20, 2020๐ As the releases before, this release has 100% test coverage.
โ Deprecration WARNING
๐ Support for Go 1.10, 1.11 and 1.12 will be dropped in a future release.
โ Theerrors.Is
anderrors.As
features greatly simplify error testing and handling and will likely be introduced in the near future.๐ Improve autocompletion behaviour.
- Pass autocompletion entries to children.
From v0.20.0 all options started being passed to children commands.
Their completion entries were missing.Separate internal option completion between flags that don't expect an argument and options that do.
When an option that expects an argument is found, the given argument won't break the completion chain.
๐ Only one argument is supported per option.Don't break autocompletion chain when there is an option in the chain that accepts an argument with
=
.
For example:program --profile=dev <tab><tab>
will show completions for program. -
v0.20.1 Changes
June 16, 2020๐ As the releases before, this release has 100% test coverage.
๐ Improve autocompletion behaviour:
Break words in COMP_LINE by matching against multiple spaces
\s+
instead of a single one. -
v0.20.0 Changes
June 09, 2020๐ As the releases before, this release has 100% test coverage.
๐ Method Deprecation
- ๐ Deprecate
opt.SetOption
Since the introduction of
opt.NewCommand(name, description string)
there is a proper parent child relationship between commands.
There is no need to hack passing desired options to the child command, instead, now all options are automatically propagated to the child.This has the side benefit to make the automated help clearer by listing all options that previously where only listed in one of the parent levels.
โก๏ธ To update, remove calls to
opt.SetOption
, for example:opt := getoptions.New() opt.Bool("help", false, opt.Alias("?")) opt.Bool("debug", false) opt.SetRequireOrder() opt.SetUnknownMode(getoptions.Pass) list := opt.NewCommand("list", "list stuff")- list.SetOption(opt.Option("help"), opt.Option("debug")).SetCommandFn(listRun)+ list.SetCommandFn(listRun) list.Bool("list-opt", false) opt.HelpCommand("") remaining, err := opt.Parse([]string{"list"})
๐ Feature Update
- ๐ Automatically run
opt.Parse
when callingopt.Dispatch
.
When defining a new command, we define the function that the command will run with
command.SetCommandFn(commandFunction)
.
๐ป If the command is passed in the command line,opt.Dispatch
calls the command function.
๐ Previously,opt.Dispatch
wasn't automatically callingopt.Parse
in the command function so the first thing that every command function had to do was a call to parse.For example:
func main() { opt := getoptions.New() list := opt.NewCommand("list", "list stuff") list.SetCommandFn(listRun) opt.HelpCommand("") remaining, err := opt.Parse(os.Args[1:]) if err != nil { ... } err = opt.Dispatch(context.Background(), "help", remaining) if err != nil { ... } }func listRun(ctx context.Context, opt \*getoptions.GetOpt, args []string) error { remaining, err := opt.Parse(args) if err != nil { ... } // Function code here}
๐ Now, the call
opt.Parse
is automated byopt.Dispatch
so the command function is simplified to:func listRun(ctx context.Context, opt \*getoptions.GetOpt, args []string) error { // Function code here}
๐ Where the received
opt
has the arguments already parsed and the receivedargs
is the remaining arguments that didn't match any option. - ๐ Deprecate
-
v0.19.0 Changes
April 04, 2020๐ As the releases before, this release has 100% test coverage.
โก๏ธ Update
opt.GetEnv
now satisfiesopt.Required
:
When an environment variable that matches the variable from
opt.GetEnv
is set,opt.GetEnv
will setopt.Called
to true and will setopt.CalledAs
to the name of the environment variable used.
In other words, when an option is required,opt.Required
is set,opt.GetEnv
satisfies that requirement.opt.GetEnv
environment variable now shows in help output.
Example:
REQUIRED PARAMETERS: --access-key-id <string> AWS Access Key ID. (env: AWS_ACCESS_KEY_ID) --role-arn <string> Role ARN. (env: AWS_ROLE_ARN) --secret-access-key <string> AWS Secret Access Key. (env: AWS_SECRET_ACCESS_KEY) OPTIONS: --region <string> Default Region. (default: "us-west-2", env: AWS_DEFAULT_REGION)
-
v0.18.0 Changes
March 25, 2020๐ As the releases before, this release has 100% test coverage.
๐ This release adds initial support for Environment Variables and adds lots of GoDoc examples.
๐ New Features
- ๐ Initial support for environment variables has been added.
๐ Currently, only
opt.String
andopt.StringVar
are supported.To use it, set the option modify function to opt.GetEnv.
For example:var profile stringopt.StringVar(&profile, "profile", "default", opt.GetEnv("AWS\_PROFILE"))
Or:
profile := opt.String("profile", "default", opt.GetEnv("AWS\_PROFILE"))
๐ NOTE: Non supported option types behave with a No-Op when
opt.GetEnv
is defined.Minor changes
๐ Change opt.Dispatch signature to clarify the actual use of the variable.
โ Additionally, actually use the variable, before it was hardcoded to "help".-func (gopt *GetOpt) Dispatch(ctx context.Context, helpOptionName string, args []string) error+func (gopt *GetOpt) Dispatch(ctx context.Context, helpCommandName string, args []string) error
-
v0.17.0 Changes
October 24, 2019๐ As the releases before, this release has 100% test coverage.
๐ This release keeps on the work of removing the kinks around subcommands.
An example showing subcommands can be found in ./examples/mygit.๐ฆ It also introduces the use of context to propagate cancelation signals, etc. to the child commands.
Finally, it introduces a new helper that captures interrupts (for example Ctrl-C) and returns a top level context.
๐ฅ Breaking changes
๐จ Refactor
NewCommmand
as a method.
This will allow the built-in help to have information about the parent.
It might also help with autocompletion.๐ Change sigature to
opt.NewCommand(name, description string)
.
It takes a name and description now.๐ Change signature of
CommandFn
to have acontext
as the first argument.
๐ฆ It will allow the parent to propagate cancelation signals, etc. to the child commands.
This change goes along a change to the helperopt.Dispatch
to also have acontext
as the first argument.โก๏ธ Updating:
- list := getoptions.NewCommand().Self("list", "list instances").+ list := opt.NewCommand("list", "list instances"). SetOption(parent.Option("help"), parent.Option("debug")). SetCommandFn(runInstanceList) list.StringSlice("tag", 1, 99, opt.Alias("t"), opt.Description("Any AWS tags you want to list"))- opt.Command(list) ...- err = opt.Dispatch("help", remaining)+ err = opt.Dispatch(context.Background(), "help", remaining) ...-func runInstanceList(opt \*getoptions.GetOpt, args []string) error {+func runInstanceList(ctx context.Context, opt \*getoptions.GetOpt, args []string) error {
๐ New Features
- ๐ฆ Introduce
opt.InterruptContext()
, a helper that returns a top level context that captures interrupt signals (os.Interrupt
,syscall.SIGHUP
,syscall.SIGTERM
).
An example can be found in ./examples/mygit.
- ๐ฆ Introduce
-
v0.16.0 Changes
September 24, 2019๐ As the releases before, this release has 100% test coverage.
๐ Fixes
- ๐ Bug Fix: Update
opt.Dispatch
not to handle--help
option.
It was preventing the help option to reach the commands.
๐ New Features
- 0๏ธโฃ Introduce
opt.HelpSynopsisArgs(string)
method to allow overriding the default args description.
0๏ธโฃ The current default description is[<args>]
.
Minor changes
- ๐ Make
SetMode
,SetUnknownMode
,SetRequireOrder
andSetMapKeysToLower
chainable.
- ๐ Bug Fix: Update