Skip to content

Conversation

@kfess
Copy link
Member

@kfess kfess commented Dec 1, 2025

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 1, 2025
@k8s-ci-robot
Copy link
Contributor

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Dec 1, 2025
@koba1t
Copy link
Member

koba1t commented Dec 14, 2025

Hi @kfess
Thanks for your contribution!

When fixing a bug, please add sufficient test cases to verify the fix and prevent regressions。

@kfess
Copy link
Member Author

kfess commented Dec 15, 2025

@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.

@kfess
Copy link
Member Author

kfess commented Dec 19, 2025

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kustomize version command: invalid --output value fails silently

3 participants