Skip to content

Commit

Permalink
feat(cmd/gno): add gno version command (#3002)
Browse files Browse the repository at this point in the history
<!-- please provide a detailed description of the changes made in this
pull request. -->

I've added the `version` command to gno to get the version of gno that
is installed

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>

---------

Co-authored-by: Morgan <[email protected]>
  • Loading branch information
kazai777 and thehowl authored Feb 5, 2025
1 parent 9e6a67b commit 0b76b0b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ GOTEST_FLAGS ?= -v -p 1 -timeout=30m
GNOROOT_DIR ?= $(abspath $(lastword $(MAKEFILE_LIST))/../../)
# We can't use '-trimpath' yet as amino use absolute path from call stack
# to find some directory: see #1236
GOBUILD_FLAGS ?= -ldflags "-X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=$(GNOROOT_DIR)"
GOBUILD_FLAGS ?= -ldflags "-X github.com/gnolang/gno/gnovm/pkg/version.Version=$(VERSION) -X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=$(GNOROOT_DIR)"
# file where to place cover profile; used for coverage commands which are
# more complex than adding -coverprofile, like test.cmd.coverage.
GOTEST_COVER_PROFILE ?= cmd-profile.out

# user for gno version [branch].[N]+[hash]
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || echo "$(shell git rev-parse --abbrev-ref HEAD).$(shell git rev-list --count HEAD)+$(shell git rev-parse --short HEAD)")

########################################
# Dev tools
.PHONY: build
Expand Down
1 change: 1 addition & 0 deletions gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func newGnocliCmd(io commands.IO) *commands.Command {
newTestCmd(io),
newToolCmd(io),
// version -- show cmd/gno, golang versions
newGnoVersionCmd(io),
// vet
)

Expand Down
24 changes: 24 additions & 0 deletions gnovm/cmd/gno/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"context"

"github.com/gnolang/gno/gnovm/pkg/version"
"github.com/gnolang/gno/tm2/pkg/commands"
)

// newVersionCmd creates a new version command
func newGnoVersionCmd(io commands.IO) *commands.Command {
return commands.NewCommand(
commands.Metadata{
Name: "version",
ShortUsage: "version",
ShortHelp: "display installed gno version",
},
nil,
func(_ context.Context, args []string) error {
io.Println("gno version:", version.Version)
return nil
},
)
}
32 changes: 32 additions & 0 deletions gnovm/cmd/gno/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"testing"

"github.com/gnolang/gno/gnovm/pkg/version"
)

func TestVersionApp(t *testing.T) {
originalVersion := version.Version

t.Cleanup(func() {
version.Version = originalVersion
})

versionValues := []string{"chain/test4.2", "develop", "master"}

testCases := make([]testMainCase, len(versionValues))
for i, v := range versionValues {
testCases[i] = testMainCase{
args: []string{"version"},
stdoutShouldContain: "gno version: " + v,
}
}

for i, testCase := range testCases {
t.Run(versionValues[i], func(t *testing.T) {
version.Version = versionValues[i]
testMainCaseRun(t, []testMainCase{testCase})
})
}
}
3 changes: 3 additions & 0 deletions gnovm/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version = "develop"

0 comments on commit 0b76b0b

Please sign in to comment.