-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 missing required flag error uses flag name and not alias #1709
Fix missing required flag error uses flag name and not alias #1709
Conversation
for _, key := range f.Names() { | ||
flagName = key | ||
flagNames := f.Names() | ||
flagName = flagNames[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if someone passes in a flag with no name or aliases defined ? Will the slice be nil ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 🦾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns an empty slice (length 0) slice with empty string (length 1), not a nil. I can make a test case for it to prove that it doesn't panic if you want, even though the code doesn't handle this kind of flag nicely (showing as a newline in the help).
What would a flag without a name or alias means to the user? Shouldn't the code have a different check and error for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(flagNames) == 0 ln 208 will panic:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skelouse it's length 1 with an empty string. Sorry for the confusion. https://go.dev/play/p/tsnBea9RKk4 - No panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both examples provided are illustrative but its better to add a simple test case for this. Just have a flag without a name and see what happens. If everything works well and good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Added another test case
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/urfave/cli/v2](https://togithub.com/urfave/cli) | require | patch | `v2.25.1` -> `v2.25.3` | --- ### Release Notes <details> <summary>urfave/cli</summary> ### [`v2.25.3`](https://togithub.com/urfave/cli/releases/tag/v2.25.3) [Compare Source](https://togithub.com/urfave/cli/compare/v2.25.2...v2.25.3) #### What's Changed - Fix `incorrectTypeForFlagError` for unknowns by [@​danhunsaker](https://togithub.com/danhunsaker) in [https://github.com/urfave/cli/pull/1708](https://togithub.com/urfave/cli/pull/1708) #### New Contributors - [@​danhunsaker](https://togithub.com/danhunsaker) made their first contribution in [https://github.com/urfave/cli/pull/1708](https://togithub.com/urfave/cli/pull/1708) **Full Changelog**: urfave/cli@v2.25.2...v2.25.3 ### [`v2.25.2`](https://togithub.com/urfave/cli/releases/tag/v2.25.2) [Compare Source](https://togithub.com/urfave/cli/compare/v2.25.1...v2.25.2) #### What's Changed - Fix missing required flag error uses flag name and not alias by [@​nirhaas](https://togithub.com/nirhaas) in [https://github.com/urfave/cli/pull/1709](https://togithub.com/urfave/cli/pull/1709) - Remove redundant variable declarations by [@​huiyifyj](https://togithub.com/huiyifyj) in [https://github.com/urfave/cli/pull/1714](https://togithub.com/urfave/cli/pull/1714) - Fix:(issue 1689) Match markdown output with help output by [@​dearchap](https://togithub.com/dearchap) in [https://github.com/urfave/cli/pull/1723](https://togithub.com/urfave/cli/pull/1723) #### New Contributors - [@​nirhaas](https://togithub.com/nirhaas) made their first contribution in [https://github.com/urfave/cli/pull/1709](https://togithub.com/urfave/cli/pull/1709) - [@​huiyifyj](https://togithub.com/huiyifyj) made their first contribution in [https://github.com/urfave/cli/pull/1714](https://togithub.com/urfave/cli/pull/1714) **Full Changelog**: urfave/cli@v2.25.1...v2.25.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/kairos-io/provider-kairos). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS42Ni4xIiwidXBkYXRlZEluVmVyIjoiMzUuNjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
What type of PR is this?
What this PR does / why we need it:
Up until now, the missing required flag error showed the last alias of a flag, instead of the actual flag name. This results in a relatively unclear error messages:
Instead of
Which issue(s) this PR fixes:
Fixes #1701
Testing
Added test case to ensure this change works as expected.
Release Notes