Skip to content

Args: false to stop passing unparsed arguments #1797

@abitrolly

Description

@abitrolly

My urfave/cli version is

2.25.7

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

#1069 requests an option to avoid printing args help when args are not used. ArgsUsage allows to customize args message, but when it is empty, the default is being printed.

Even with such option, args will still be passed to function when user specifies them by mistake.

The proposal is to add boolean Args option that will both turn off the args help message, and will make it an error to pass arguments.

@@ -22,9 +22,11 @@ type statsFlags struct {
 func statsCommand() cli.Command {
        var statsFlags statsFlags
        stats := cli.Command{
                Name:      "stats",
                Usage:     "Output useful statistics about a SCIP index",
+               Args:      false,
+               ArgsUsage: " ",
                Flags:     []cli.Flag{fromFlag(&statsFlags.from)},
                Action: func(c *cli.Context) error {
                        return statsMain(statsFlags)
                },

To reproduce

https://cli.urfave.org/v2/getting-started/ should error out if Args: false and user supplied undefined argument.

Observed behavior

Specifying undefined arguments do not make any errors.

Expected behavior

Error out.

Additional context

Want to fix this yourself?

Maybe.

Run go version and paste its output here

# paste `go version` output in here

Run go env and paste its output here

# paste `go env` output in here

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions