Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions make/info.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION)
YEAR_GEN := $(shell date '+%Y')

GOBIN := $(shell go env GOPATH)/bin
GIT_COMMIT := $(shell git rev-parse --short HEAD)
KPT_VERSION := $(shell date '+development-%Y-%m-%dT%H:%M:%S')
Comment thread
aravindtga marked this conversation as resolved.

export KPT_FN_WASM_RUNTIME ?= nodejs

LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${GIT_COMMIT}
LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${KPT_VERSION}
Comment thread
aravindtga marked this conversation as resolved.
ifeq ($(OS),Windows_NT)
# Do nothing
else
Expand Down
35 changes: 32 additions & 3 deletions run/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 The kpt Authors
// Copyright 2019,2026 The kpt Authors
Comment thread
aravindtga marked this conversation as resolved.
Comment thread
aravindtga marked this conversation as resolved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime/debug"
"strconv"
"strings"

Expand Down Expand Up @@ -104,6 +105,7 @@ func GetMain(ctx context.Context) *cobra.Command {

replace(cmd)

versionCmd.Flags().Bool("short", false, "Print only the concise version identifier")
Comment thread
aravindtga marked this conversation as resolved.
cmd.AddCommand(versionCmd)
hideFlags(cmd)
return cmd
Expand Down Expand Up @@ -158,8 +160,35 @@ var version = "unknown"
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of kpt",
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("%s\n", version)
Run: func(cmd *cobra.Command, _ []string) {
var hash, dirty string
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
hash = setting.Value
case "vcs.modified":
if strings.ToLower(setting.Value) == "true" {
dirty = " (dirty)"
}
}
}
}
Comment thread
aravindtga marked this conversation as resolved.

short, _ := cmd.Flags().GetBool("short")
if short {
if version == "unknown" && len(hash) >= 7 {
fmt.Printf("%s\n", hash[:7])
} else {
fmt.Printf("%s\n", version)
}
return
}
fmt.Printf("Version: %s\n", version)
if hash == "" {
hash = "unknown"
}
fmt.Printf("Git commit: %s%s\n", hash, dirty)
Comment thread
aravindtga marked this conversation as resolved.
},
}

Expand Down
Loading