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(cli): inconsistent behavior across CLI flags, environment variables, and config files #5843

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented Dec 31, 2023

Description

In a recent update to Trivy, we introduced validation and alias functionalities for CLI flags. However, we realized that these enhancements had not been uniformly applied to other configuration methods, specifically environment variables and the configuration file (trivy.yaml). This PR addresses this oversight by extending the validation and alias features across all configuration settings, ensuring consistency and improved usability.

To facilitate this integration, we've added a Parse() method. This method is designed to be called before accessing values through the Value() method, mirroring the interface pattern found in the Go's standard flag package (flag package documentation). This addition ensures that value retrieval does not result in errors and that the parsing process is streamlined across different settings.

Additionally, we've refactored the handling of default flag values. Previously, the logic was branched based on the type of the Default field of each flag. We've now shifted this approach to leverage Go's generics, allowing for a more explicit and type-safe representation of default values.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@knqyf263 knqyf263 self-assigned this Dec 31, 2023
@knqyf263
Copy link
Collaborator Author

knqyf263 commented Jan 6, 2024

@naortalmor1 @tonaim I believe it requires small changes on your end, but please let me know if it has a big impact. We'll consider another approach in that case.

@knqyf263 knqyf263 marked this pull request as ready for review January 6, 2024 06:48
@knqyf263 knqyf263 requested a review from DmitriyLewen January 6, 2024 06:48
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM.
Left nit comment.

integration/config_test.go Show resolved Hide resolved
@knqyf263
Copy link
Collaborator Author

@naortalmor1 @tonaim No comments? Can I push on this change?

@knqyf263 knqyf263 added this pull request to the merge queue Feb 1, 2024
Merged via the queue into aquasecurity:main with commit 59e5433 Feb 1, 2024
12 checks passed
@knqyf263 knqyf263 deleted the fix/validate_envs branch February 1, 2024 03:47
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.

Inconsistent behavior of --scanners aliases across CLI flags, environment variables, and config files
2 participants