Merge pull request #2614 from nspcc-dev/version-output-format

cli: change --version output format, fix #2611
This commit is contained in:
Roman Khimov 2022-07-27 17:39:14 +03:00 committed by GitHub
commit 0ae8b635a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -1,7 +1,9 @@
package main package main
import ( import (
"fmt"
"os" "os"
"runtime"
"github.com/nspcc-dev/neo-go/cli/query" "github.com/nspcc-dev/neo-go/cli/query"
"github.com/nspcc-dev/neo-go/cli/server" "github.com/nspcc-dev/neo-go/cli/server"
@ -21,7 +23,15 @@ func main() {
} }
} }
func versionPrinter(c *cli.Context) {
_, _ = fmt.Fprintf(c.App.Writer, "NeoGo\nVersion: %s\nGoVersion: %s\n",
config.Version,
runtime.Version(),
)
}
func newApp() *cli.App { func newApp() *cli.App {
cli.VersionPrinter = versionPrinter
ctl := cli.NewApp() ctl := cli.NewApp()
ctl.Name = "neo-go" ctl.Name = "neo-go"
ctl.Version = config.Version ctl.Version = config.Version

View file

@ -7,6 +7,8 @@ import (
func TestCLIVersion(t *testing.T) { func TestCLIVersion(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
e.Run(t, "neo-go", "--version") e.Run(t, "neo-go", "--version")
e.checkNextLine(t, "^neo-go version") e.checkNextLine(t, "^NeoGo")
e.checkNextLine(t, "^Version:")
e.checkNextLine(t, "^GoVersion:")
e.checkEOF(t) e.checkEOF(t)
} }