frostfs-node/cmd/neofs-cli/modules/version.go
Stanislav Bogatyrev 246a15de35 cli: Add empty neofs-cli app structure
In the following release `neofs-cli` will be used to directly manage NeoFS Node.
All required definitions and interfaces are also moving from `neofs-api` to
`neofs-node` repository, so it's more convinient to have `neofs-cli` here.

Signed-off-by: Stanislav Bogatyrev <stanislav@nspcc.ru>
2020-10-02 11:25:35 +03:00

47 lines
970 B
Go

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)
}