Skip to content

Support WithDefault method #4

@ocavue

Description

@ocavue

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions