Skip to content

Commit

Permalink
Just replace broken main output with semver and deprecate short flag …
Browse files Browse the repository at this point in the history
…as is
  • Loading branch information
KnVerey committed Feb 1, 2023
1 parent 2950321 commit 681f21f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
12 changes: 6 additions & 6 deletions api/provenance/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func GetProvenance() Provenance {
return p
}

// Full returns the full provenance stamp.
func (v Provenance) Full() string {
return fmt.Sprintf("%+v", v)
}

// Short returns the semantic version.
func (v Provenance) Short() string {
return v.Semver()
return fmt.Sprintf(
"%v",
Provenance{
Version: v.Version,
BuildDate: v.BuildDate,
})
}

// Semver returns the semantic version of kustomize.
Expand Down
13 changes: 3 additions & 10 deletions api/provenance/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const expectedVersionFromLdFlag = "(test)"
func TestGetProvenance(t *testing.T) {
p := provenance.GetProvenance()
// These are set by ldflags in our Makefile
assert.Equal(t, "(test)", p.Version)
assert.Equal(t, expectedVersionFromLdFlag, p.Version)
assert.Equal(t, expectedBuildDateFromLdFlag, p.BuildDate)
// This comes from BuildInfo, which is not set during go test: https://github.com/golang/go/issues/33976
assert.Equal(t, "unknown", p.GitCommit)
Expand All @@ -31,17 +31,10 @@ func TestGetProvenance(t *testing.T) {
func TestProvenance_Short(t *testing.T) {
p := provenance.GetProvenance()
// The version not set during go test, so this comes from an ldflag: https://github.com/golang/go/issues/33976
assert.Equal(t, "(test)", p.Short())
assert.Equal(t, fmt.Sprintf("{%s %s }", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag), p.Short())

p.Version = "kustomize/v4.11.12"
assert.Equal(t, "v4.11.12", p.Short())
}

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

func TestProvenance_Semver(t *testing.T) {
Expand Down
7 changes: 2 additions & 5 deletions kustomize/commands/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewCmdVersion(w io.Writer) *cobra.Command {
}

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

0 comments on commit 681f21f

Please sign in to comment.