cli
cli copied to clipboard
Support `WithDefault` method
This issue is a feature request
Both Arg and Option don't support default value now. In order to do that, I can write something like below:
installCommand := cli.NewCommand("install", "Install a package").
WithOption(
cli.NewOption("retry", "maximal retry times (default: 3)").WithType(cli.TypeInt),
).
WithArg(
cli.NewArg("package", "package name").WithType(cli.TypeString),
).
WithAction(func(args []string, options map[string]string) int {
if _, ok := options["retry"]; !ok {
options["retry"] = "3"
}
// do something
})
With WithDefault method, I can write the default value 3 for only one time and avert a conflict between the actual code and the doc.
Should be easy to implement. Want to submit a pull request?