Thank you!
It does handle subcommands, I should write an example of that. In short, you use RegisterNew to create a new getopt.Set or RegisterSet to register with a previously created set. You will have to call set.Parse to parse the args to the subcommand. If you need to parse a particular set multiple times that has default values then you will want to use Dup. Also, you probably want a named structure. Something like this (beware, I have not compiled this code):
Example with no global defaults
type cmdOpts struct { … }
v, set := options.RegisterNew(“command”, &cmdOpts{})
opts := v.(*cmdOpts)
set.Parse(args)
Example with global and local defaults:
type cmdOpts struct {
Name string `getopt:"--name=NAME name of the widget"`
Count int `getopt:"--count -c=COUNT number of widgets"`
}
var cmdGlobalOpts = &cmdOpts {
Name: “global”,
}
opts := options.Dup(&cmdGlobalOpts).(*cmdOpts)
opts.Count = 42
v, set := options.RegisterNew(“command”, opts)
set.Parse(args)
I will try to get an example added to the codebase in the next week or so.
BTW, my hope is that in most common cases you can just use the options packages. You can also use github.com/pborman/getopt/v2 in conjunction with the options package if need be.
-Paul
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.