From f67f186930f96b4c43e1d37769dc2875d16917a0 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:58:23 +0100 Subject: [PATCH] chore: reorganize gnovm/cmd/gno (#3587) - Increase Go-Gno compatibility. - Sort alphabetically commands. - Move Gno-specific commands under `gno tool `. - Improve `ShortHelp`. - Use `embedmd` in `gnovm/cmd/gno`'s README as an example of how we should use it more frequently. --------- Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .github/workflows/examples.yml | 2 +- .gitignore | 3 + CONTRIBUTING.md | 2 +- docs/reference/go-gno-compatibility.md | 56 +++++++++---------- examples/Makefile | 6 +- gnovm/Makefile | 10 +++- gnovm/cmd/gno/README.md | 24 ++++++-- gnovm/cmd/gno/bug.go | 2 +- gnovm/cmd/gno/clean.go | 2 +- gnovm/cmd/gno/doc.go | 3 +- gnovm/cmd/gno/env.go | 2 +- gnovm/cmd/gno/fmt.go | 2 +- gnovm/cmd/gno/main.go | 29 +++++----- gnovm/cmd/gno/mod.go | 6 +- gnovm/cmd/gno/run.go | 2 +- gnovm/cmd/gno/test.go | 2 +- gnovm/cmd/gno/testdata/lint/bad_import.txtar | 4 +- gnovm/cmd/gno/testdata/lint/file_error.txtar | 4 +- gnovm/cmd/gno/testdata/lint/no_error.txtar | 4 +- gnovm/cmd/gno/testdata/lint/no_gnomod.txtar | 4 +- .../cmd/gno/testdata/lint/not_declared.txtar | 4 +- .../transpile/gobuild_flag_build_error.txtar | 4 +- .../transpile/gobuild_flag_parse_error.txtar | 4 +- .../testdata/transpile/invalid_import.txtar | 4 +- .../cmd/gno/testdata/transpile/no_args.txtar | 4 +- .../gno/testdata/transpile/parse_error.txtar | 4 +- .../testdata/transpile/valid_empty_dir.txtar | 4 +- .../transpile/valid_gobuild_file.txtar | 4 +- .../transpile/valid_gobuild_flag.txtar | 6 +- .../transpile/valid_output_flag.txtar | 8 +-- .../transpile/valid_output_gobuild.txtar | 8 +-- .../transpile/valid_transpile_file.txtar | 6 +- .../transpile/valid_transpile_package.txtar | 4 +- .../transpile/valid_transpile_tree.txtar | 4 +- gnovm/cmd/gno/tool.go | 39 +++++++++++++ gnovm/cmd/gno/{lint.go => tool_lint.go} | 0 .../gno/{lint_test.go => tool_lint_test.go} | 20 +++---- gnovm/cmd/gno/{repl.go => tool_repl.go} | 0 .../gno/{repl_test.go => tool_repl_test.go} | 0 .../gno/{transpile.go => tool_transpile.go} | 0 ...anspile_test.go => tool_transpile_test.go} | 0 gnovm/tests/challenges/unused0.gno | 2 +- 42 files changed, 181 insertions(+), 117 deletions(-) create mode 100644 gnovm/cmd/gno/tool.go rename gnovm/cmd/gno/{lint.go => tool_lint.go} (100%) rename gnovm/cmd/gno/{lint_test.go => tool_lint_test.go} (70%) rename gnovm/cmd/gno/{repl.go => tool_repl.go} (100%) rename gnovm/cmd/gno/{repl_test.go => tool_repl_test.go} (100%) rename gnovm/cmd/gno/{transpile.go => tool_transpile.go} (100%) rename gnovm/cmd/gno/{transpile_test.go => tool_transpile_test.go} (100%) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 5d606a2a663..ffe40c2db7e 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -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 diff --git a/.gitignore b/.gitignore index 7d3f3f92b41..82cc109887e 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ coverage.out *.swp *.swo *.bak + +.tmp/ +wal/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b58d63c6c75..9562a531227 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/docs/reference/go-gno-compatibility.md b/docs/reference/go-gno-compatibility.md index 9f9d611e4fd..87c734d935f 100644 --- a/docs/reference/go-gno-compatibility.md +++ b/docs/reference/go-gno-compatibility.md @@ -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. | +| 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 | diff --git a/examples/Makefile b/examples/Makefile index cdc73ee6b3a..63a20f78eb9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -33,11 +33,11 @@ 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: @@ -45,7 +45,7 @@ test: .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: diff --git a/gnovm/Makefile b/gnovm/Makefile index babb7ad74ca..ce745e44aae 100644 --- a/gnovm/Makefile +++ b/gnovm/Makefile @@ -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: @@ -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 diff --git a/gnovm/cmd/gno/README.md b/gnovm/cmd/gno/README.md index f900b164783..81b45622c05 100644 --- a/gnovm/cmd/gno/README.md +++ b/gnovm/cmd/gno/README.md @@ -6,13 +6,25 @@ `gno [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 [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 diff --git a/gnovm/cmd/gno/bug.go b/gnovm/cmd/gno/bug.go index a1273d9ad59..7a4345fb1ed 100644 --- a/gnovm/cmd/gno/bug.go +++ b/gnovm/cmd/gno/bug.go @@ -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: diff --git a/gnovm/cmd/gno/clean.go b/gnovm/cmd/gno/clean.go index 0ca2e940d58..7c318c3957e 100644 --- a/gnovm/cmd/gno/clean.go +++ b/gnovm/cmd/gno/clean.go @@ -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 { diff --git a/gnovm/cmd/gno/doc.go b/gnovm/cmd/gno/doc.go index 794dd1ba7bb..c34ed984d9c 100644 --- a/gnovm/cmd/gno/doc.go +++ b/gnovm/cmd/gno/doc.go @@ -29,7 +29,8 @@ func newDocCmd(io commands.IO) *commands.Command { commands.Metadata{ Name: "doc", ShortUsage: "doc [flags] ", - 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 { diff --git a/gnovm/cmd/gno/env.go b/gnovm/cmd/gno/env.go index 9c601a270c7..20d32c85ec0 100644 --- a/gnovm/cmd/gno/env.go +++ b/gnovm/cmd/gno/env.go @@ -18,7 +18,7 @@ func newEnvCmd(io commands.IO) *commands.Command { commands.Metadata{ Name: "env", ShortUsage: "env [flags] ", - ShortHelp: "`env` prints Gno environment information", + ShortHelp: "print gno environment information", }, c, func(_ context.Context, args []string) error { diff --git a/gnovm/cmd/gno/fmt.go b/gnovm/cmd/gno/fmt.go index de6c28c4df0..e37c50a079f 100644 --- a/gnovm/cmd/gno/fmt.go +++ b/gnovm/cmd/gno/fmt.go @@ -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.", }, cfg, diff --git a/gnovm/cmd/gno/main.go b/gnovm/cmd/gno/main.go index 7a5799f2835..5f8bb7b522e 100644 --- a/gnovm/cmd/gno/main.go +++ b/gnovm/cmd/gno/main.go @@ -16,33 +16,32 @@ func main() { func newGnocliCmd(io commands.IO) *commands.Command { cmd := commands.NewCommand( commands.Metadata{ - ShortUsage: " [flags] [...]", - LongHelp: "Runs the gno development toolkit", + ShortUsage: "gno [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 diff --git a/gnovm/cmd/gno/mod.go b/gnovm/cmd/gno/mod.go index 5479d934ce6..f303908d8ee 100644 --- a/gnovm/cmd/gno/mod.go +++ b/gnovm/cmd/gno/mod.go @@ -25,7 +25,7 @@ func newModCmd(io commands.IO) *commands.Command { commands.Metadata{ Name: "mod", ShortUsage: "mod ", - ShortHelp: "manage gno.mod", + ShortHelp: "module maintenance", }, commands.NewEmptyConfig(), commands.HelpExec, @@ -33,8 +33,12 @@ func newModCmd(io commands.IO) *commands.Command { cmd.AddSubCommands( newModDownloadCmd(io), + // edit + // graph newModInitCmd(), newModTidy(io), + // vendor + // verify newModWhy(io), ) diff --git a/gnovm/cmd/gno/run.go b/gnovm/cmd/gno/run.go index 9a9beac5cd1..489016aa3d4 100644 --- a/gnovm/cmd/gno/run.go +++ b/gnovm/cmd/gno/run.go @@ -32,7 +32,7 @@ func newRunCmd(io commands.IO) *commands.Command { commands.Metadata{ Name: "run", ShortUsage: "run [flags] [...]", - ShortHelp: "runs the specified gno files", + ShortHelp: "run gno packages", }, cfg, func(_ context.Context, args []string) error { diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index ea06b25d8e2..ae67d69bc90 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -35,7 +35,7 @@ func newTestCmd(io commands.IO) *commands.Command { commands.Metadata{ Name: "test", ShortUsage: "test [flags] [...]", - 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 diff --git a/gnovm/cmd/gno/testdata/lint/bad_import.txtar b/gnovm/cmd/gno/testdata/lint/bad_import.txtar index e2c0431443c..117a699fa6c 100644 --- a/gnovm/cmd/gno/testdata/lint/bad_import.txtar +++ b/gnovm/cmd/gno/testdata/lint/bad_import.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/lint/file_error.txtar b/gnovm/cmd/gno/testdata/lint/file_error.txtar index 4fa50c6da81..f3301b46757 100644 --- a/gnovm/cmd/gno/testdata/lint/file_error.txtar +++ b/gnovm/cmd/gno/testdata/lint/file_error.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/lint/no_error.txtar b/gnovm/cmd/gno/testdata/lint/no_error.txtar index 5dd3b164952..5033e054ac6 100644 --- a/gnovm/cmd/gno/testdata/lint/no_error.txtar +++ b/gnovm/cmd/gno/testdata/lint/no_error.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/lint/no_gnomod.txtar b/gnovm/cmd/gno/testdata/lint/no_gnomod.txtar index b5a046a7095..4564f2d9fff 100644 --- a/gnovm/cmd/gno/testdata/lint/no_gnomod.txtar +++ b/gnovm/cmd/gno/testdata/lint/no_gnomod.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/lint/not_declared.txtar b/gnovm/cmd/gno/testdata/lint/not_declared.txtar index ac56b27e0df..3c3c304797e 100644 --- a/gnovm/cmd/gno/testdata/lint/not_declared.txtar +++ b/gnovm/cmd/gno/testdata/lint/not_declared.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/transpile/gobuild_flag_build_error.txtar b/gnovm/cmd/gno/testdata/transpile/gobuild_flag_build_error.txtar index 145fe796c09..0b41319a190 100644 --- a/gnovm/cmd/gno/testdata/transpile/gobuild_flag_build_error.txtar +++ b/gnovm/cmd/gno/testdata/transpile/gobuild_flag_build_error.txtar @@ -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' diff --git a/gnovm/cmd/gno/testdata/transpile/gobuild_flag_parse_error.txtar b/gnovm/cmd/gno/testdata/transpile/gobuild_flag_parse_error.txtar index 629de2b7f3d..1008d45adb2 100644 --- a/gnovm/cmd/gno/testdata/transpile/gobuild_flag_parse_error.txtar +++ b/gnovm/cmd/gno/testdata/transpile/gobuild_flag_parse_error.txtar @@ -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$' diff --git a/gnovm/cmd/gno/testdata/transpile/invalid_import.txtar b/gnovm/cmd/gno/testdata/transpile/invalid_import.txtar index 0c51012feb7..23e9e805fe5 100644 --- a/gnovm/cmd/gno/testdata/transpile/invalid_import.txtar +++ b/gnovm/cmd/gno/testdata/transpile/invalid_import.txtar @@ -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$' diff --git a/gnovm/cmd/gno/testdata/transpile/no_args.txtar b/gnovm/cmd/gno/testdata/transpile/no_args.txtar index 6d8592d4e3b..30ea24fbf73 100644 --- a/gnovm/cmd/gno/testdata/transpile/no_args.txtar +++ b/gnovm/cmd/gno/testdata/transpile/no_args.txtar @@ -1,6 +1,6 @@ -# Run gno transpile without args +# Run gno tool transpile without args -! gno transpile +! gno tool transpile ! stdout .+ stderr 'USAGE' diff --git a/gnovm/cmd/gno/testdata/transpile/parse_error.txtar b/gnovm/cmd/gno/testdata/transpile/parse_error.txtar index b94b86992af..c19276ef273 100644 --- a/gnovm/cmd/gno/testdata/transpile/parse_error.txtar +++ b/gnovm/cmd/gno/testdata/transpile/parse_error.txtar @@ -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$' diff --git a/gnovm/cmd/gno/testdata/transpile/valid_empty_dir.txtar b/gnovm/cmd/gno/testdata/transpile/valid_empty_dir.txtar index 2bd1841d2b4..f9ccd8d8b53 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_empty_dir.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_empty_dir.txtar @@ -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 .+ diff --git a/gnovm/cmd/gno/testdata/transpile/valid_gobuild_file.txtar b/gnovm/cmd/gno/testdata/transpile/valid_gobuild_file.txtar index 40bb1ecb98a..8e95c5994d0 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_gobuild_file.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_gobuild_file.txtar @@ -1,6 +1,6 @@ -# Run gno transpile with -gobuild flag on an individual file +# Run gno tool transpile with -gobuild flag on an individual file -gno transpile -gobuild -v main.gno +gno tool transpile -gobuild -v main.gno ! stdout .+ cmp stderr stderr.golden diff --git a/gnovm/cmd/gno/testdata/transpile/valid_gobuild_flag.txtar b/gnovm/cmd/gno/testdata/transpile/valid_gobuild_flag.txtar index 2eacfb9de60..72ca7a4f2f4 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_gobuild_flag.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_gobuild_flag.txtar @@ -1,6 +1,6 @@ -# Run gno transpile with -gobuild flag +# Run gno tool transpile with -gobuild flag -gno transpile -gobuild -v . +gno tool transpile -gobuild -v . ! stdout .+ cmp stderr stderr.golden @@ -12,7 +12,7 @@ cmp sub/sub.gno.gen.go sub/sub.gno.gen.go.golden rm mai.gno.gen.gosub/sub.gno.gen.go # Re-try, but use an absolute path. -gno transpile -gobuild -v $WORK +gno tool transpile -gobuild -v $WORK ! stdout .+ cmpenv stderr stderr2.golden diff --git a/gnovm/cmd/gno/testdata/transpile/valid_output_flag.txtar b/gnovm/cmd/gno/testdata/transpile/valid_output_flag.txtar index b1a63890f46..62953e96fb7 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_output_flag.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_output_flag.txtar @@ -1,6 +1,6 @@ -# Run gno transpile with valid gno files, using the -output flag. +# Run gno tool transpile with valid gno files, using the -output flag. -gno transpile -v -output directory/hello/ . +gno tool transpile -v -output directory/hello/ . ! stdout .+ cmp stderr stderr1.golden @@ -9,7 +9,7 @@ exists directory/hello/main.gno.gen.go rm directory # Try running using the absolute path to the directory. -gno transpile -v -output directory/hello $WORK +gno tool transpile -v -output directory/hello $WORK ! stdout .+ cmpenv stderr stderr2.golden @@ -20,7 +20,7 @@ rm directory # Try running in subdirectory, using a "relative non-local path." (ie. has "../") mkdir subdir cd subdir -gno transpile -v -output hello .. +gno tool transpile -v -output hello .. ! stdout .+ cmpenv stderr ../stderr3.golden diff --git a/gnovm/cmd/gno/testdata/transpile/valid_output_gobuild.txtar b/gnovm/cmd/gno/testdata/transpile/valid_output_gobuild.txtar index 3540e865f3e..c948e53ebb3 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_output_gobuild.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_output_gobuild.txtar @@ -1,6 +1,6 @@ -# Run gno transpile with valid gno files, using the -output and -gobuild flags together. +# Run gno tool transpile with valid gno files, using the -output and -gobuild flags together. -gno transpile -v -output directory/hello/ -gobuild . +gno tool transpile -v -output directory/hello/ -gobuild . ! stdout .+ cmp stderr stderr1.golden @@ -9,7 +9,7 @@ exists directory/hello/main.gno.gen.go rm directory # Try running using the absolute path to the directory. -gno transpile -v -output directory/hello -gobuild $WORK +gno tool transpile -v -output directory/hello -gobuild $WORK ! stdout .+ cmpenv stderr stderr2.golden @@ -20,7 +20,7 @@ rm directory # Try running in subdirectory, using a "relative non-local path." (ie. has "../") mkdir subdir cd subdir -gno transpile -v -output hello -gobuild .. +gno tool transpile -v -output hello -gobuild .. ! stdout .+ cmpenv stderr ../stderr3.golden diff --git a/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar b/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar index 86cc6f12f7a..906c43cc41b 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_transpile_file.txtar @@ -1,8 +1,8 @@ -# Run gno transpile with an individual file. +# Run gno tool transpile with an individual file. # Running transpile on the current directory should only precompile # main.gno. -gno transpile -v . +gno tool transpile -v . ! stdout .+ stderr ^\.$ @@ -12,7 +12,7 @@ exists main.gno.gen.go rm main.gno.gen.go # Running it using individual filenames should precompile hello_test.gno, as well. -gno transpile -v main.gno hello_test.gno +gno tool transpile -v main.gno hello_test.gno ! stdout .+ cmp stderr transpile-files-stderr.golden diff --git a/gnovm/cmd/gno/testdata/transpile/valid_transpile_package.txtar b/gnovm/cmd/gno/testdata/transpile/valid_transpile_package.txtar index 2a24423598a..74923b9846a 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_transpile_package.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_transpile_package.txtar @@ -1,6 +1,6 @@ -# Run gno transpile with valid gno files +# Run gno tool transpile with valid gno files -gno transpile . +gno tool transpile . ! stdout .+ ! stderr .+ diff --git a/gnovm/cmd/gno/testdata/transpile/valid_transpile_tree.txtar b/gnovm/cmd/gno/testdata/transpile/valid_transpile_tree.txtar index a765ab5093b..e0c42d986e4 100644 --- a/gnovm/cmd/gno/testdata/transpile/valid_transpile_tree.txtar +++ b/gnovm/cmd/gno/testdata/transpile/valid_transpile_tree.txtar @@ -1,7 +1,7 @@ -# Run gno transpile with dependencies +# Run gno tool transpile with dependencies env GNOROOT=$WORK -gno transpile -v ./examples +gno tool transpile -v ./examples ! stdout .+ cmpenv stderr stderr.golden diff --git a/gnovm/cmd/gno/tool.go b/gnovm/cmd/gno/tool.go new file mode 100644 index 00000000000..0e4f7ff51d7 --- /dev/null +++ b/gnovm/cmd/gno/tool.go @@ -0,0 +1,39 @@ +package main + +import ( + "github.com/gnolang/gno/tm2/pkg/commands" +) + +func newToolCmd(io commands.IO) *commands.Command { + cmd := commands.NewCommand( + commands.Metadata{ + Name: "tool", + ShortUsage: "gno tool command [args...]", + ShortHelp: "run specified gno tool", + }, + commands.NewEmptyConfig(), + commands.HelpExec, + ) + + cmd.AddSubCommands( + // go equivalent commands: + // + // compile + // transpile + // pprof + // trace + // vet + + // gno specific commands: + // + // ast + newLintCmd(io), + // publish/release + // render -- call render()? + newReplCmd(), + newTranspileCmd(io), + // "vm" -- starts an in-memory chain that can be interacted with? + ) + + return cmd +} diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/tool_lint.go similarity index 100% rename from gnovm/cmd/gno/lint.go rename to gnovm/cmd/gno/tool_lint.go diff --git a/gnovm/cmd/gno/lint_test.go b/gnovm/cmd/gno/tool_lint_test.go similarity index 70% rename from gnovm/cmd/gno/lint_test.go rename to gnovm/cmd/gno/tool_lint_test.go index 4589fc55f92..85b625fa367 100644 --- a/gnovm/cmd/gno/lint_test.go +++ b/gnovm/cmd/gno/tool_lint_test.go @@ -8,26 +8,26 @@ import ( func TestLintApp(t *testing.T) { tc := []testMainCase{ { - args: []string{"lint"}, + args: []string{"tool", "lint"}, errShouldBe: "flag: help requested", }, { - args: []string{"lint", "../../tests/integ/run_main/"}, + args: []string{"tool", "lint", "../../tests/integ/run_main/"}, stderrShouldContain: "./../../tests/integ/run_main: gno.mod file not found in current or any parent directory (code=1)", errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/undefined_variable_test/undefined_variables_test.gno"}, + args: []string{"tool", "lint", "../../tests/integ/undefined_variable_test/undefined_variables_test.gno"}, stderrShouldContain: "undefined_variables_test.gno:6:28: name toto not declared (code=2)", errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/package_not_declared/main.gno"}, + args: []string{"tool", "lint", "../../tests/integ/package_not_declared/main.gno"}, stderrShouldContain: "main.gno:4:2: name fmt not declared (code=2)", errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/several-lint-errors/main.gno"}, + args: []string{"tool", "lint", "../../tests/integ/several-lint-errors/main.gno"}, stderrShouldContain: "../../tests/integ/several-lint-errors/main.gno:5:5: expected ';', found example (code=2)\n../../tests/integ/several-lint-errors/main.gno:6", errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/several-files-multiple-errors/main.gno"}, + args: []string{"tool", "lint", "../../tests/integ/several-files-multiple-errors/main.gno"}, stderrShouldContain: func() string { lines := []string{ "../../tests/integ/several-files-multiple-errors/file2.gno:3:5: expected 'IDENT', found '{' (code=2)", @@ -39,17 +39,17 @@ func TestLintApp(t *testing.T) { }(), errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/minimalist_gnomod/"}, + args: []string{"tool", "lint", "../../tests/integ/minimalist_gnomod/"}, // TODO: raise an error because there is a gno.mod, but no .gno files }, { - args: []string{"lint", "../../tests/integ/invalid_module_name/"}, + args: []string{"tool", "lint", "../../tests/integ/invalid_module_name/"}, // TODO: raise an error because gno.mod is invalid }, { - args: []string{"lint", "../../tests/integ/invalid_gno_file/"}, + args: []string{"tool", "lint", "../../tests/integ/invalid_gno_file/"}, stderrShouldContain: "../../tests/integ/invalid_gno_file/invalid.gno:1:1: expected 'package', found packag (code=2)", errShouldBe: "exit code: 1", }, { - args: []string{"lint", "../../tests/integ/typecheck_missing_return/"}, + args: []string{"tool", "lint", "../../tests/integ/typecheck_missing_return/"}, stderrShouldContain: "../../tests/integ/typecheck_missing_return/main.gno:5:1: missing return (code=4)", errShouldBe: "exit code: 1", }, diff --git a/gnovm/cmd/gno/repl.go b/gnovm/cmd/gno/tool_repl.go similarity index 100% rename from gnovm/cmd/gno/repl.go rename to gnovm/cmd/gno/tool_repl.go diff --git a/gnovm/cmd/gno/repl_test.go b/gnovm/cmd/gno/tool_repl_test.go similarity index 100% rename from gnovm/cmd/gno/repl_test.go rename to gnovm/cmd/gno/tool_repl_test.go diff --git a/gnovm/cmd/gno/transpile.go b/gnovm/cmd/gno/tool_transpile.go similarity index 100% rename from gnovm/cmd/gno/transpile.go rename to gnovm/cmd/gno/tool_transpile.go diff --git a/gnovm/cmd/gno/transpile_test.go b/gnovm/cmd/gno/tool_transpile_test.go similarity index 100% rename from gnovm/cmd/gno/transpile_test.go rename to gnovm/cmd/gno/tool_transpile_test.go diff --git a/gnovm/tests/challenges/unused0.gno b/gnovm/tests/challenges/unused0.gno index d5b0ff75c17..dc9aa950dec 100644 --- a/gnovm/tests/challenges/unused0.gno +++ b/gnovm/tests/challenges/unused0.gno @@ -1,7 +1,7 @@ package main // NOTE: instead of patching the vm code, this should be handled by an -// integration of `gno transpile --gobuild`, which uses `go build` under +// integration of `gno tool transpile --gobuild`, which uses `go build` under // the hood and already detects unused variables. func main() { var x int