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: Print the long options of the required flags missing #1126

Merged
merged 2 commits into from May 2, 2020

Conversation

oleorhagen
Copy link
Contributor

What type of PR is this?

(REQUIRED)

  • [ x] bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

This fixes a formatting bug in the v1 required flags error message

Which issue(s) this PR fixes:

Formatting error in the requireflags error message

Special notes for your reviewer:

I at least think this is a bug. The short option behaviour is a little odd.

Testing

Only tested manually, see the commit message for output.

Release Notes

Changes the error message printing the long option for the required flags missing, and not the alias.

@oleorhagen oleorhagen requested a review from a team as a code owner May 1, 2020 15:55
@oleorhagen
Copy link
Contributor Author

Also, would it be an idea to export the requiredFlagsError type?

Copy link
Member

@rliebz rliebz left a comment

Choose a reason for hiding this comment

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

This looks correct, but it's not clear from the MR description what this is fixing.

Please add a regression test to prove that this change fixes the incorrect behavior you were seeing.

context.go Outdated Show resolved Hide resolved
@rliebz
Copy link
Member

rliebz commented May 2, 2020

As a note, if we end up accepting this, I believe it is relevant for the v2/master branch as well.

Ole Petter added 2 commits May 2, 2020 19:47
This adds a test verifying that the requiredFlagsError does contain the long
option of the missing flag, instead of the short option and a space, which was
the old behaviour.

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
The error message collected by 'checkRequiredFlags()' now sets the name of the flags
to the long option given in the 'Name: <somecommand>' field.

This change is introduced to fix up an error where printing the error in the
case of a missing required flag looks like:

```
Required flags " n,  t" not set
```

Whilst the expected behaviour is:

```
Required flags "<long-name1>, <long-name2>" not set
```

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
@oleorhagen
Copy link
Contributor Author

As a note, if we end up accepting this, I believe it is relevant for the v2/master branch as well.

Acrually, I was not able to reproduce this on master. The code has changed a little though, so the explicit string splitting is not done anylonger, and the name is returned directly, so the situation seems to be fine there. I did cherry the test over just to be sure, and it passed. Do you still want a PR for it on master (the test only that is).

@rliebz
Copy link
Member

rliebz commented May 2, 2020

@oleorhagen Thanks for checking v2 as well. If you wanted to submit a PR to add the test case to master, that would be awesome!

@rliebz rliebz merged commit 1e44266 into urfave:v1 May 2, 2020
oleorhagen pushed a commit to oleorhagen/cli that referenced this pull request May 3, 2020
StringSliceFlag needs to be a pointer, and not a struct.

See: urfave#1126 for a description of the regression
tested for.

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
oleorhagen pushed a commit to oleorhagen/cli that referenced this pull request May 3, 2020
StringSliceFlag needs to be a pointer, and not a struct. Also formatted the test.

See: urfave#1126 for a description of the regression
tested for.

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
@oleorhagen oleorhagen mentioned this pull request May 3, 2020
4 tasks
erikwilson pushed a commit to rancher/spur that referenced this pull request Jun 8, 2020
StringSliceFlag needs to be a pointer, and not a struct. Also formatted the test.

See: urfave/cli#1126 for a description of the regression
tested for.

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
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.

None yet

2 participants