Skip to content

v0.30.0: New Features

Latest
Compare
Choose a tag to compare
@DavidGamba DavidGamba released this 22 Feb 06:29

As the releases before, this release has 100% test coverage.
Tested with Go 1.16, 1.17, 1.18, 1.19, 1.20, 1.21 and 1.22.

New Features

  • Add opt.SetValue to allow setting the value of an option.

  • Add opt.SuggestedValues ModifyFn to allow setting autocompletion suggestions for an option.

Works just like the existing opt.ValidValues but it doesn't error out if the value is not in the list of suggestions.

  • Add opt.GetRequiredArg, opt.GetRequiredArgInt and opt.GetRequiredArgFloat64 to simplify handling required arguments and providing error messages.

For example:

	opt := getoptions.New()
	opt.SetCommandFn(Run)
	opt.HelpSynopsisArg("<arg1>", "arg1 desc")
	opt.HelpSynopsisArg("<arg2>", "arg2 desc")

...

func Run(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
	i, args, err := opt.GetRequiredArgInt(args)
	if err != nil {
		return err
	}
	...
	return nil
}

If the argument is not provided, the error message will be:

ERROR: Missing required argument: <arg1>

If the argument is provided but it is not an integer, the error message will be:

ERROR: Argument error: Can't convert string to int: 'x'