From bece968988ce7dddb727d20a7cbae5b34576c7bd Mon Sep 17 00:00:00 2001 From: jianli-97 Date: Fri, 15 Sep 2023 08:58:20 +0800 Subject: [PATCH] add version cmd --- app/cmd/cmd.go | 1 + app/cmd/version.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 app/cmd/version.go diff --git a/app/cmd/cmd.go b/app/cmd/cmd.go index 36e84b7..434e464 100755 --- a/app/cmd/cmd.go +++ b/app/cmd/cmd.go @@ -34,6 +34,7 @@ func NewNkdCommand(in io.Reader, out, err io.Writer) *cobra.Command { cmds.AddCommand(NewUpgradeCommand()) // TODO: 当前extend是指扩展到的worker节点个数,后续应改成想扩展的worker节点个数。 cmds.AddCommand(NewExtendCommand()) + cmds.AddCommand(NewVersionCommand()) return cmds } diff --git a/app/cmd/version.go b/app/cmd/version.go new file mode 100644 index 0000000..6df652e --- /dev/null +++ b/app/cmd/version.go @@ -0,0 +1,44 @@ +/* +Copyright 2023 KylinSoft Co., Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "runtime" + + "github.com/spf13/cobra" +) + +func NewVersionCommand() *cobra.Command { + var ( + version = "0.1.0" + goVersion = runtime.Version() + arch = fmt.Sprint(runtime.GOOS, "/", runtime.GOARCH) + ) + + cmd := &cobra.Command{ + Use: "version", + Short: "Display the NKD version information", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Version: %s\n", version) + fmt.Printf("Go Version: %s\n", goVersion) + fmt.Printf("OS/Arch: %s\n", arch) + }, + } + + return cmd +} -- Gitee