-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathversion.go
More file actions
34 lines (30 loc) · 933 Bytes
/
version.go
File metadata and controls
34 lines (30 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cmd
import (
"fmt"
"log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// versionCmd represents the version command, which displays version information
// about the pvtr build including version, commit hash, and build time.
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display version details.",
Long: `Display the version, git commit hash, and build timestamp of this pvtr build. Use the --verbose flag to see all details.`,
Run: func(cmd *cobra.Command, args []string) {
if viper.GetBool("verbose") {
_, _ = fmt.Fprintf(writer, "Version:\t%s\n", buildVersion)
_, _ = fmt.Fprintf(writer, "Commit:\t%s\n", buildGitCommitHash)
_, _ = fmt.Fprintf(writer, "Build Time:\t%s\n", buildTime)
err := writer.Flush()
if err != nil {
log.Printf("Error flushing writer: %v", err)
}
} else {
fmt.Println(buildVersion)
}
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}