code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/software_version.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package cmd 17 18 import ( 19 "fmt" 20 "io" 21 "os" 22 23 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/cli" 24 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/flags" 25 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/printer" 26 coreversion "code.vegaprotocol.io/vega/version" 27 wversion "code.vegaprotocol.io/vega/wallet/version" 28 29 "github.com/spf13/cobra" 30 ) 31 32 var ( 33 softwareVersionLong = cli.LongDesc(` 34 Get the version of the software and checks if its compatibility with the 35 registered networks. 36 37 This is NOT related to the wallet version. To get information about the wallet, 38 use the "info" command. 39 `) 40 41 softwareVersionExample = cli.Examples(` 42 # Get the version of the software 43 {{.Software}} software version 44 `) 45 ) 46 47 type GetSoftwareVersionHandler func() *wversion.GetSoftwareVersionResponse 48 49 func NewCmdSoftwareVersion(w io.Writer, rf *RootFlags) *cobra.Command { 50 return BuildCmdGetSoftwareVersion(w, wversion.GetSoftwareVersionInfo, rf) 51 } 52 53 func BuildCmdGetSoftwareVersion(w io.Writer, handler GetSoftwareVersionHandler, rf *RootFlags) *cobra.Command { 54 cmd := &cobra.Command{ 55 Use: "version", 56 Short: "Get the version of the software", 57 Long: softwareVersionLong, 58 Example: softwareVersionExample, 59 RunE: func(_ *cobra.Command, _ []string) error { 60 resp := handler() 61 62 switch rf.Output { 63 case flags.InteractiveOutput: 64 PrintGetSoftwareVersionResponse(w, resp) 65 case flags.JSONOutput: 66 return printer.FprintJSON(w, resp) 67 } 68 69 return nil 70 }, 71 } 72 73 return cmd 74 } 75 76 func PrintGetSoftwareVersionResponse(w io.Writer, resp *wversion.GetSoftwareVersionResponse) { 77 p := printer.NewInteractivePrinter(w) 78 79 str := p.String() 80 defer p.Print(str) 81 82 if wversion.IsUnreleased() { 83 str.CrossMark().DangerText("You are running an unreleased version of the software (").DangerText(coreversion.Get()).DangerText(").").NextLine() 84 str.Pad().DangerText("Use it at your own risk!").NextSection() 85 } 86 87 str.Text("Software version:").NextLine().WarningText(resp.Version).NextSection() 88 str.Text("Git hash:").NextLine().WarningText(resp.GitHash).NextSection() 89 90 str.RedArrow().DangerText("Important").NextLine() 91 str.Text("The software version is NOT related to the key derivation version of your wallets.").NextLine() 92 str.Bold("The software managing the wallets should not be confused with the wallets themselves.").NextLine() 93 str.Text("To get the key derivation version of a wallet, see the following command:").NextSection() 94 str.Code(fmt.Sprintf("%s describe --help", os.Args[0])).NextLine() 95 96 str.BlueArrow().InfoText("Check the network compatibility").NextLine() 97 str.Text("To determine if this software is compatible with the registered networks, use the following command:").NextSection() 98 str.Code(fmt.Sprintf("%s software compatibility", os.Args[0])).NextLine() 99 }