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

Don't allow negative value to be passed for --max-results flag #33

Merged
merged 2 commits into from Mar 9, 2024

Conversation

mmourick
Copy link
Collaborator

@mmourick mmourick commented Mar 9, 2024

What

  • Add PreRun to list subcommand to validate user input is non-negative

Why

  • Fixes a runtime error when negative values are passed.

References

Copy link
Member

@bschaatsbergen bschaatsbergen left a comment

Choose a reason for hiding this comment

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

Would using a PreRun in Cobra not be nicer to handle the negative value, in that case we can show our own error message instead of a Go exception?

@mmourick
Copy link
Collaborator Author

mmourick commented Mar 9, 2024

@bschaatsbergen the Cobra message wasn't too bad imo, but I agree our own message is nicer and more consistent with the rest of the tool.

Cobra validation:

Error: invalid argument "-5" for "--max-results" flag: strconv.ParseUint: parsing "-5": invalid syntax

PreRun validation implemented in 4fe90e7

error: --max-results cannot be negative: see `tfversion list -h` for help and examples

Copy link
Member

@bschaatsbergen bschaatsbergen left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@bschaatsbergen bschaatsbergen merged commit df2975d into main Mar 9, 2024
4 checks passed
@bschaatsbergen bschaatsbergen deleted the fix/input-validation-max-results-flag branch March 9, 2024 21:51
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.

Negative max-results yields an out of bound
2 participants