|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package cmd |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "runtime" |
| 22 | + |
| 23 | + "github.com/spf13/cobra" |
| 24 | +) |
| 25 | + |
| 26 | +// Version information |
| 27 | +var ( |
| 28 | + // AppVersion is the version of the application |
| 29 | + appVersion = "v0.0.0-dev" |
| 30 | + |
| 31 | + // BuildTime is the time the application was built |
| 32 | + buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format |
| 33 | + |
| 34 | + // GitCommit is the commit hash of the build |
| 35 | + gitCommit string |
| 36 | +) |
| 37 | + |
| 38 | +var versionCmd = &cobra.Command{ |
| 39 | + Use: "version", |
| 40 | + Short: "print current version", |
| 41 | + Run: func(_ *cobra.Command, _ []string) { |
| 42 | + fmt.Printf("Version:\t%s\n", appVersion) |
| 43 | + fmt.Printf("BuildTime:\t%s\n", buildDate) |
| 44 | + fmt.Printf("GitCommit:\t%s\n", gitCommit) |
| 45 | + fmt.Printf("GoVersion:\t%s\n", runtime.Version()) |
| 46 | + fmt.Printf("Compiler:\t%s\n", runtime.Compiler) |
| 47 | + fmt.Printf("OS/Arch:\t%s/%s\n", runtime.GOOS, runtime.GOARCH) |
| 48 | + }, |
| 49 | +} |
| 50 | + |
| 51 | +func init() { |
| 52 | + RootCmd.AddCommand(versionCmd) |
| 53 | +} |
0 commit comments