mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 05:02:50 +00:00
Handle -version flag on all commands
Tested: Passed -version argument to kubelet (and all other binaries): $ output/go/bin/kubecfg -version Kubernetes version 0.1, build 6454a541fd56 Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
@@ -16,6 +16,16 @@ limitations under the License.
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
versionFlag = flag.Bool("version", false, "Print version information and quit")
|
||||
)
|
||||
|
||||
// Info contains versioning information.
|
||||
// TODO: Add []string of api versions supported? It's still unclear
|
||||
// how we'll want to distribute that information.
|
||||
@@ -34,3 +44,17 @@ func Get() Info {
|
||||
GitCommit: commitFromGit,
|
||||
}
|
||||
}
|
||||
|
||||
// String returns info as a human-friendly version string.
|
||||
func (info Info) String() string {
|
||||
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, info.GitCommit)
|
||||
}
|
||||
|
||||
// PrintAndExitIfRequested will check if the -version flag was passed
|
||||
// and, if so, print the version and exit.
|
||||
func PrintAndExitIfRequested() {
|
||||
if *versionFlag {
|
||||
fmt.Printf("Kubernetes %s\n", Get())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user