Add default case to handle invalid `--output` flag in version command
Description
Add default case for invalid --output flag in version command
When users specify an invalid value for the --output flag (e.g., --output=yml),
the command fails silently with no error message or output.
This PR adds a default case to the switch statement that returns a clear error message, matching the error handling pattern used in kubectl version.
Output after adding default block
$ kustomize version --output=yml
Error: --output must be 'yaml' or 'json'
Usage:
kustomize version [flags]
Examples:
kustomize version
Flags:
-h, --help help for version
-o, --output string One of 'yaml' or 'json'.
Global Flags:
--stack-trace print a stack-trace on error
exit status 1
Fixes #6032
Additional context
This is my first contribution to the kustomize codebase. Please let me know if there's anything I should adjust to better align with the project's conventions.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: kfess Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
Hi @kfess Thanks for your contribution!
When fixing a bug, please add sufficient test cases to verify the fix and prevent regressions。
@koba1t Thank you for the feedback. I will add test cases to verify the fix and prevent regressions. Please review them once I've updated the PR.
@koba1t
I'd like to confirm the expected error output behavior when an invalid --output value is provided.
Current behavior
kubectl:
$ kubectl version --output=yml
error: --output must be 'yaml' or 'json'
kustomize (current behavior shows help text as well):
$ kustomize version --output=yml
Error: --output must be 'yaml' or 'json'
Usage:
kustomize version [flags]
Examples:
kustomize version
Flags:
-h, --help help for version
-o, --output string One of 'yaml' or 'json'.
Global Flags:
--stack-trace print a stack-trace on error
exit status 1
I believe the kubectl behavior (showing only the error message without the usage/help text) is better for this case. Is this understanding correct? Should I modify my PR to suppress the usage output on validation errors, matching kubectl's behavior and add test for it?