Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variadic args #1865

Merged
merged 4 commits into from
Feb 15, 2024
Merged

Fix variadic args #1865

merged 4 commits into from
Feb 15, 2024

Conversation

joshfrench
Copy link
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

Fixes the following:

  • If variadic args are passed, only the first is captured because Parse exits early when comparing count >= -1.
  • If no args are passed, default values are clobbered by the empty set.

Special notes for your reviewer:

If more arguments are defined after an unbounded argument, the end user may experience an error:

Arguments: []cli.Argument{
    &cli.StringArg{
        Name: "First",
        Max: -1,
    },
    &cli.StringArg{
        Name: "Second,
    },
}

After First is parsed, there will be no remaining args. If Second.Min == 0, it will just use its default/zero value. If Second.Min > 0, this will result in an insufficient arg count error. Both of those behaviors seem intuitive to me, but we could also add a runtime check and proactively error if an unbounded arg is defined as anything other than the last argument.

Testing

Unit tests updated with cases for variadic args.

Release Notes

Variadic args are now parsed correctly.

Copy link
Contributor

@dearchap dearchap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments

args.go Show resolved Hide resolved
args_test.go Outdated Show resolved Hide resolved
@dearchap dearchap merged commit 5336fa4 into urfave:main Feb 15, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants