Skip to content

Commit 681f21f

Browse files
committed
Just replace broken main output with semver and deprecate short flag as is
1 parent 2950321 commit 681f21f

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

api/provenance/provenance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ func GetProvenance() Provenance {
6565
return p
6666
}
6767

68-
// Full returns the full provenance stamp.
69-
func (v Provenance) Full() string {
70-
return fmt.Sprintf("%+v", v)
71-
}
72-
7368
// Short returns the semantic version.
7469
func (v Provenance) Short() string {
75-
return v.Semver()
70+
return fmt.Sprintf(
71+
"%v",
72+
Provenance{
73+
Version: v.Version,
74+
BuildDate: v.BuildDate,
75+
})
7676
}
7777

7878
// Semver returns the semantic version of kustomize.

api/provenance/provenance_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const expectedVersionFromLdFlag = "(test)"
1717
func TestGetProvenance(t *testing.T) {
1818
p := provenance.GetProvenance()
1919
// These are set by ldflags in our Makefile
20-
assert.Equal(t, "(test)", p.Version)
20+
assert.Equal(t, expectedVersionFromLdFlag, p.Version)
2121
assert.Equal(t, expectedBuildDateFromLdFlag, p.BuildDate)
2222
// This comes from BuildInfo, which is not set during go test: https://github.com/golang/go/issues/33976
2323
assert.Equal(t, "unknown", p.GitCommit)
@@ -31,17 +31,10 @@ func TestGetProvenance(t *testing.T) {
3131
func TestProvenance_Short(t *testing.T) {
3232
p := provenance.GetProvenance()
3333
// The version not set during go test, so this comes from an ldflag: https://github.com/golang/go/issues/33976
34-
assert.Equal(t, "(test)", p.Short())
34+
assert.Equal(t, fmt.Sprintf("{%s %s }", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag), p.Short())
3535

3636
p.Version = "kustomize/v4.11.12"
37-
assert.Equal(t, "v4.11.12", p.Short())
38-
}
39-
40-
func TestProvenance_Full(t *testing.T) {
41-
p := provenance.GetProvenance()
42-
// Most values are not set during go test: https://github.com/golang/go/issues/33976
43-
assert.Contains(t, p.Full(), fmt.Sprintf("{Version:%s GitCommit:unknown BuildDate:%s", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag))
44-
assert.Regexp(t, "GoOs:\\w+ GoArch:\\w+ GoVersion:go1", p.Full())
37+
assert.Equal(t, fmt.Sprintf("{kustomize/v4.11.12 %s }", expectedBuildDateFromLdFlag), p.Short())
4538
}
4639

4740
func TestProvenance_Semver(t *testing.T) {

kustomize/commands/version/version.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewCmdVersion(w io.Writer) *cobra.Command {
4040
}
4141

4242
versionCmd.Flags().BoolVar(&o.Short, "short", false, "short form")
43-
_ = versionCmd.Flags().MarkDeprecated("short", "and will be removed in the future. The --short output will become the default.")
43+
_ = versionCmd.Flags().MarkDeprecated("short", "and will be removed in the future.")
4444
versionCmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "One of 'yaml' or 'json'.")
4545
return &versionCmd
4646
}
@@ -67,10 +67,7 @@ func (o *Options) Run() error {
6767
if o.Short {
6868
fmt.Fprintln(o.Writer, provenance.GetProvenance().Short())
6969
} else {
70-
fmt.Fprintln(os.Stderr, "WARNING: This version information is deprecated and "+
71-
"will be replaced with the output from kustomize version --short. "+
72-
"Use --output=yaml|json to get the full version.")
73-
fmt.Fprintln(o.Writer, provenance.GetProvenance().Full())
70+
fmt.Fprintln(o.Writer, provenance.GetProvenance().Semver())
7471
}
7572
case "yaml":
7673
marshalled, err := yaml.Marshal(provenance.GetProvenance())

0 commit comments

Comments
 (0)