Skip to content

Commit fd7352d

Browse files
committed
version: error on invalid --output instead of silent success
Invalid values like --output=yml previously exited 0 with no output. Return a clear error matching kubectl's --output validation. Signed-off-by: dpacgdm <dpac.gdm@gmail.com>
1 parent f7d33c2 commit fd7352d

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

kustomize/commands/version/version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (o *Options) Run() error {
8181
return errors.WrapPrefixf(err, "marshalling provenance to json")
8282
}
8383
fmt.Fprintln(o.Writer, string(marshalled))
84+
default:
85+
return fmt.Errorf("--output must be 'yaml' or 'json'")
8486
}
8587
return nil
8688
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2026 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package version
5+
6+
import (
7+
"bytes"
8+
"strings"
9+
"testing"
10+
)
11+
12+
func TestRunInvalidOutput(t *testing.T) {
13+
var buf bytes.Buffer
14+
o := NewOptions(&buf)
15+
o.Output = "yml"
16+
err := o.Run()
17+
if err == nil {
18+
t.Fatal("expected error for invalid --output")
19+
}
20+
if !strings.Contains(err.Error(), "--output must be 'yaml' or 'json'") {
21+
t.Fatalf("unexpected error: %v", err)
22+
}
23+
if buf.Len() != 0 {
24+
t.Fatalf("expected no output on invalid --output, got %q", buf.String())
25+
}
26+
}

0 commit comments

Comments
 (0)