Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorganize gnovm/cmd/gno #3587

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
go-version: ${{ matrix.goversion }}
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno transpile -v --gobuild ./examples
- run: go run ./gnovm/cmd/gno tool transpile -v --gobuild ./examples
test:
strategy:
fail-fast: false
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ coverage.out
*.swp
*.swo
*.bak

.tmp/
wal/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Additionally, it's not possible to use `gofumpt` for code formatting with
(flycheck-define-checker gno-lint
"A GNO syntax checker using the gno lint tool."
:command ("gno" "lint" source-original)
:command ("gno" "tool" "lint" source-original)
:error-patterns (;; ./file.gno:32: error message (code=1)
(error line-start (file-name) ":" line ": " (message) " (code=" (id (one-or-more digit)) ")." line-end))
;; Ensure the file is saved, to work around
Expand Down
56 changes: 28 additions & 28 deletions docs/reference/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,31 +297,31 @@ Legend:

## Tooling (`gno` binary)

| go command | gno command | comment |
|-------------------|---------------------------|-----------------------------------------------------------------------|
| go bug | gno bug | same behavior |
| go build | gno transpile -gobuild | same intention, limited compatibility |
| go clean | gno clean | same intention, limited compatibility |
| go doc | gno doc | limited compatibility; see https://github.com/gnolang/gno/issues/522 |
| go env | gno env | |
| go fix | | |
| go fmt | gno fmt | gofmt (& similar tools, like gofumpt) works on gno code. |
| go generate | | |
| go get | | see `gno mod download`. |
| go help | gno $cmd --help | ie. `gno doc --help` |
| go install | | |
| go list | | |
| go mod | gno mod | |
| + go mod init | gno mod init | same behavior |
| + go mod download | gno mod download | same behavior |
| + go mod tidy | gno mod tidy | same behavior |
| + go mod why | gno mod why | same intention |
| | gno transpile | |
| go work | | |
| | gno repl | |
| go run | gno run | |
| go test | gno test | limited compatibility |
| go tool | | |
| go version | | |
| go vet | | |
| golint | gno lint | same intention |
| go command | gno command | comment |
|-------------------|------------------------------|-----------------------------------------------------------------------|
| go bug | gno bug | same behavior |
| go build | gno tool transpile -gobuild | same intention, limited compatibility |
| go clean | gno clean | same intention, limited compatibility |
| go doc | gno doc | limited compatibility; see https://github.com/gnolang/gno/issues/522 |
| go env | gno env | |
| go fix | | |
| go fmt | gno fmt | gofmt (& similar tools, like gofumpt) works on gno code. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important to note that it includes import by default compared to the original go fmt, so it will try to format and resolve dependencies. (It should not fail)

| go generate | | |
| go get | | see `gno mod download`. |
| go help | gno $cmd --help | ie. `gno doc --help` |
| go install | | |
| go list | | |
| go mod | gno mod | |
| + go mod init | gno mod init | same behavior |
| + go mod download | gno mod download | same behavior |
| + go mod tidy | gno mod tidy | same behavior |
| + go mod why | gno mod why | same intention |
| | gno tool transpile | |
| go work | | |
| | gno tool repl | |
| go run | gno run | |
| go test | gno test | limited compatibility |
| go tool | | |
| go version | | |
| go vet | | |
| golint | gno tool lint | same intention |
6 changes: 3 additions & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ OFFICIAL_PACKAGES += ./gno.land/r/gov
# Dev tools
.PHONY: transpile
transpile:
go run ../gnovm/cmd/gno transpile -v .
go run ../gnovm/cmd/gno tool transpile -v .

.PHONY: build
build:
go run ../gnovm/cmd/gno transpile -v --gobuild .
go run ../gnovm/cmd/gno tool transpile -v --gobuild .

.PHONY: test
test:
go run ../gnovm/cmd/gno test -v ./...

.PHONY: lint
lint:
go run ../gnovm/cmd/gno lint -v $(OFFICIAL_PACKAGES)
go run ../gnovm/cmd/gno tool lint -v $(OFFICIAL_PACKAGES)

.PHONY: test.sync
test.sync:
Expand Down
10 changes: 8 additions & 2 deletions gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ lint:

.PHONY: fmt
fmt:
go run ./cmd/gno fmt $(GNOFMT_FLAGS) ./stdlibs/... ./tests/stdlibs/...
$(rundep) mvdan.cc/gofumpt $(GOFMT_FLAGS) .
go run ./cmd/gno fmt $(GNOFMT_FLAGS) ./stdlibs/... ./tests/stdlibs/...

.PHONY: imports
imports:
Expand Down Expand Up @@ -125,7 +125,13 @@ _test.filetest:;
# TODO: move _dev.stringer to go:generate instructions, simplify generate
# to just go generate.
.PHONY: generate
generate: _dev.stringer _dev.generate
generate: _dev.stringer _dev.generate _dev.docs

.PHONY: _dev.docs
_dev.docs:
mkdir -p .tmp
(go run ./cmd/gno -h 2>&1 || true) | grep -v "exit status 1" > .tmp/gno-help.txt
$(rundep) github.com/campoy/embedmd -w `find . -name "*.md"`

stringer_cmd=$(rundep) golang.org/x/tools/cmd/stringer
.PHONY: _dev.stringer
Expand Down
24 changes: 18 additions & 6 deletions gnovm/cmd/gno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@

`gno <command> [arguments]`

## Commands
## Usage

* `gno run` - run a Gno file
* `gno transpile` - transpile .gno to .go
* `gno test` - test a gno package
* `gno mod` - manages dependencies
* `gno repl` start a GnoVM REPL
[embedmd]:#(../../.tmp/gno-help.txt)
```txt
USAGE
gno <command> [arguments]

SUBCOMMANDS
bug start a bug report
clean remove generated and cached data
doc show documentation for package or symbol
env print gno environment information
fmt gnofmt (reformat) package sources
mod module maintenance
run run gno packages
test test packages
tool run specified gno tool

```

## Install

Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newBugCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "bug",
ShortUsage: "bug",
ShortHelp: "Start a bug report",
ShortHelp: "start a bug report",
LongHelp: `opens https://github.com/gnolang/gno/issues in a browser.

The new issue body is prefilled for you with the following information:
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newCleanCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "clean",
ShortUsage: "clean [flags]",
ShortHelp: "removes generated files and cached data",
ShortHelp: "remove generated and cached data",
},
cfg,
func(ctx context.Context, args []string) error {
Expand Down
3 changes: 2 additions & 1 deletion gnovm/cmd/gno/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func newDocCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "doc",
ShortUsage: "doc [flags] <pkgsym>",
ShortHelp: "get documentation for the specified package or symbol (type, function, method, or variable/constant)",
ShortHelp: "show documentation for package or symbol",
LongHelp: "get documentation for the specified package or symbol (type, function, method, or variable/constant)",
},
c,
func(_ context.Context, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func newEnvCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "env",
ShortUsage: "env [flags] <pkgsym>",
ShortHelp: "`env` prints Gno environment information",
ShortHelp: "print gno environment information",
},
c,
func(_ context.Context, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newFmtCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "fmt",
ShortUsage: "gno fmt [flags] [path ...]",
ShortHelp: "Run gno file formatter.",
ShortHelp: "gnofmt (reformat) package sources",
LongHelp: "The `gno fmt` tool processes, formats, and cleans up `gno` source files.",
Comment on lines +38 to 39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should mention it here as well

},
cfg,
Expand Down
29 changes: 14 additions & 15 deletions gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,32 @@ func main() {
func newGnocliCmd(io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "<subcommand> [flags] [<arg>...]",
LongHelp: "Runs the gno development toolkit",
ShortUsage: "gno <command> [arguments]",
},
commands.NewEmptyConfig(),
commands.HelpExec,
)

cmd.AddSubCommands(
newModCmd(io),
newTestCmd(io),
newLintCmd(io),
newRunCmd(io),
newTranspileCmd(io),
newBugCmd(io),
// build
newCleanCmd(io),
newReplCmd(),
newDocCmd(io),
newEnvCmd(io),
newBugCmd(io),
// fix
newFmtCmd(io),
// graph
// vendor -- download deps from the chain in vendor/
// list -- list packages
// render -- call render()?
// publish/release
// generate
// "vm" -- starts an in-memory chain that can be interacted with?
// get
// install
// list -- list packages
newModCmd(io),
// work
newRunCmd(io),
// telemetry
newTestCmd(io),
newToolCmd(io),
// version -- show cmd/gno, golang versions
// vet
)

return cmd
Expand Down
6 changes: 5 additions & 1 deletion gnovm/cmd/gno/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ func newModCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "mod",
ShortUsage: "mod <command>",
ShortHelp: "manage gno.mod",
ShortHelp: "module maintenance",
},
commands.NewEmptyConfig(),
commands.HelpExec,
)

cmd.AddSubCommands(
newModDownloadCmd(io),
// edit
// graph
newModInitCmd(),
newModTidy(io),
// vendor
// verify
newModWhy(io),
)

Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newRunCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "run",
ShortUsage: "run [flags] <file> [<file>...]",
ShortHelp: "runs the specified gno files",
ShortHelp: "run gno packages",
},
cfg,
func(_ context.Context, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newTestCmd(io commands.IO) *commands.Command {
commands.Metadata{
Name: "test",
ShortUsage: "test [flags] <package> [<package>...]",
ShortHelp: "runs the tests for the specified packages",
ShortHelp: "test packages",
LongHelp: `Runs the tests for the specified packages.
'gno test' recompiles each package along with any files with names matching the
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/lint/bad_import.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testing gno lint command: bad import error
# testing gno tool lint command: bad import error

! gno lint ./bad_file.gno
! gno tool lint ./bad_file.gno

cmp stdout stdout.golden
cmp stderr stderr.golden
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/lint/file_error.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gno lint: test file error
# gno tool lint: test file error

! gno lint ./i_have_error_test.gno
! gno tool lint ./i_have_error_test.gno

cmp stdout stdout.golden
cmp stderr stderr.golden
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/lint/no_error.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testing simple gno lint command with any error
# testing simple gno tool lint command with any error

gno lint ./good_file.gno
gno tool lint ./good_file.gno

cmp stdout stdout.golden
cmp stdout stderr.golden
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/lint/no_gnomod.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gno lint: no gnomod
# gno tool lint: no gnomod

! gno lint .
! gno tool lint .

cmp stdout stdout.golden
cmp stderr stderr.golden
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/lint/not_declared.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testing gno lint command: not declared error
# testing gno tool lint command: not declared error

! gno lint ./bad_file.gno
! gno tool lint ./bad_file.gno

cmp stdout stdout.golden
cmp stderr stderr.golden
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Run gno transpile with -gobuild flag
# Run gno tool transpile with -gobuild flag
# The error messages changed sometime in go1.23, so this avoids errors

! gno transpile -gobuild .
! gno tool transpile -gobuild .

! stdout .+
stderr '^main.gno:4:6: .*declared and not used'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run gno transpile with -gobuild flag on file with parse error
# Run gno tool transpile with -gobuild flag on file with parse error

! gno transpile -gobuild .
! gno tool transpile -gobuild .

! stdout .+
stderr '^main.gno:3:1: expected declaration, found invalid$'
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/transpile/invalid_import.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run gno transpile with gno files with an invalid import path
# Run gno tool transpile with gno files with an invalid import path

! gno transpile .
! gno tool transpile .

! stdout .+
stderr '^main.gno:5:2: import "xxx" does not exist$'
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/transpile/no_args.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run gno transpile without args
# Run gno tool transpile without args

! gno transpile
! gno tool transpile

! stdout .+
stderr 'USAGE'
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/transpile/parse_error.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run gno transpile with gno files with parse errors
# Run gno tool transpile with gno files with parse errors

! gno transpile .
! gno tool transpile .

! stdout .+
stderr '^main.gno:3:1: expected declaration, found invalid$'
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/transpile/valid_empty_dir.txtar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run gno transpile on an empty dir
# Run gno tool transpile on an empty dir

gno transpile .
gno tool transpile .

! stdout .+
! stderr .+
Loading
Loading