From 87ce64fbbb8e6752381bbbd512319cf792567a2f Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Sun, 20 Jun 2021 19:11:49 +0300 Subject: [PATCH] [#624] cli/root: Delete `version` command and add corresponding flag Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/root.go | 20 +++++++++++++- cmd/neofs-cli/modules/version.go | 47 -------------------------------- 2 files changed, 19 insertions(+), 48 deletions(-) delete mode 100644 cmd/neofs-cli/modules/version.go diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 4ebcc55c5..e40282faf 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -17,6 +17,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-node/misc" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -48,6 +49,7 @@ It contains commands for interaction with NeoFS nodes using different versions of neofs-api and some useful utilities for compiling ACL rules from JSON notation, managing container access through protocol gates, querying network map and much more!`, + Run: entryPoint, } var ( @@ -107,7 +109,23 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. - // rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.Flags().Bool("version", false, "Application version and NeoFS API compatibility") +} + +func entryPoint(cmd *cobra.Command, _ []string) { + printVersion, _ := cmd.Flags().GetBool("version") + if printVersion { + cmd.Printf( + "Version: %s \nBuild: %s \nDebug: %s\n", + misc.Version, + misc.Build, + misc.Debug, + ) + + return + } + + _ = cmd.Usage() } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/neofs-cli/modules/version.go b/cmd/neofs-cli/modules/version.go deleted file mode 100644 index 48fa940d2..000000000 --- a/cmd/neofs-cli/modules/version.go +++ /dev/null @@ -1,47 +0,0 @@ -package cmd - -import ( - "encoding/json" - "fmt" - - "github.com/nspcc-dev/neofs-node/misc" - - "github.com/spf13/cobra" -) - -var ( - // versionCmd represents the version command - versionCmd = &cobra.Command{ - Use: "version", - Short: "Print version and exit", - Run: versionRun, - } -) - -var flagJSON bool - -type VersionInfo struct { - Version string `json:"Version,omitempty"` - Build string `json:"Build,omitempty"` - Debug string `json:"Debug,omitempty"` -} - -func init() { - rootCmd.AddCommand(versionCmd) - versionCmd.Flags().BoolVarP(&flagJSON, "json", "j", false, "Print version information in JSON") -} - -func versionRun(cmd *cobra.Command, args []string) { - versionInfo := VersionInfo{Version: misc.Version, Build: misc.Build, Debug: misc.Debug} - - if flagJSON { - bytes, _ := json.Marshal(versionInfo) - fmt.Printf("%s", string(bytes)+"\n") - return - } - - fmt.Printf("Version: %s \nBuild: %s \nDebug: %s\n", - versionInfo.Version, - versionInfo.Build, - versionInfo.Debug) -}