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

Dont check required flags until command action is executed #1975

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

dearchap
Copy link
Contributor

@dearchap dearchap commented Oct 2, 2024

What type of PR is this?

(REQUIRED)

  • feature

What this PR does / why we need it:

(REQUIRED)

Working towards making all the flags appear in any order in the cli

Which issue(s) this PR fixes:

(REQUIRED)

Special notes for your reviewer:

(fill-in or delete this section)

Testing

(fill-in or delete this section)

Added a new test TestRequiredFlagDelayed

go test -run=TestRequiredFlagDelayed

Release Notes

(REQUIRED)

This allows users to access help without having to provide all required flags for each of the commands

@dearchap dearchap requested a review from a team as a code owner October 2, 2024 14:03
Copy link
Member

@Juneezee Juneezee left a comment

Choose a reason for hiding this comment

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

We can reduce some typings here by using table-driven test style like the TestFlagDuplicates below. What do you think?

cli/command_test.go

Lines 2971 to 2995 in 31c5c84

func TestFlagDuplicates(t *testing.T) {
tests := []struct {
name string
args []string
errExpected bool
}{
{
name: "all args present once",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10"},
},
{
name: "duplicate non slice flag(duplicatable)",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--iflag", "20"},
},
{
name: "duplicate non slice flag(non duplicatable)",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--sflag", "trip"},
errExpected: true,
},
{
name: "duplicate slice flag(non duplicatable)",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--fsflag", "3.0", "--iflag", "10"},
errExpected: true,
},
}

command_test.go Outdated Show resolved Hide resolved
@dearchap dearchap requested a review from Juneezee October 3, 2024 23:24
Copy link
Member

@Juneezee Juneezee left a comment

Choose a reason for hiding this comment

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

👍

@dearchap dearchap merged commit 20ef97b into urfave:main Oct 4, 2024
13 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