kustomize icon indicating copy to clipboard operation
kustomize copied to clipboard

Add default case to handle invalid `--output` flag in version command

Open kfess opened this issue 3 weeks ago • 3 comments

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.

kfess avatar Dec 01 '25 15:12 kfess

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

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 avatar Dec 01 '25 15:12 k8s-ci-robot

Hi @kfess Thanks for your contribution!

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

koba1t avatar Dec 14 '25 19:12 koba1t

@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 avatar Dec 15 '25 09:12 kfess

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

kfess avatar Dec 19 '25 14:12 kfess