Skip to content

Commit

Permalink
gnodev run initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon authored and moul committed Jan 30, 2023
1 parent 195bca4 commit 51c410d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.PHONY: logos goscan gnoland gnokey gnofaucet logos reset gnoweb gnotxport
all: build

build: gnoland gnokey goscan logos gnoweb gnotxport gnofaucet
build: gnoland gnokey gnodev goscan logos gnoweb gnotxport gnofaucet

install: install_gnodev install_gnokey

Expand Down
8 changes: 7 additions & 1 deletion cmd/gnodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type (
)

var mainApps AppList = []AppItem{
{
App: runApp,
Name: "run",
Desc: "run a Gno file",
Defaults: defaultRunOptions,
},
{
App: buildApp,
Name: "build",
Expand Down Expand Up @@ -55,7 +61,7 @@ var mainApps AppList = []AppItem{
// graph
// vendor -- download deps from the chain in vendor/
// list -- list packages
// run -- call render(), or maybe create a new main?
// render -- call render()?
// publish/release
// generate
// doc -- godoc
Expand Down
1 change: 1 addition & 0 deletions cmd/gnodev/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func runRepl(rootDir string, verbose bool) error {
}
m := gno.NewMachineWithOptions(gno.MachineOptions{
PkgPath: "test",
Output: stdout,
Store: testStore,
})

Expand Down
68 changes: 68 additions & 0 deletions cmd/gnodev/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"os"

"github.com/gnolang/gno/pkgs/command"
"github.com/gnolang/gno/pkgs/errors"
gno "github.com/gnolang/gno/pkgs/gnolang"
"github.com/gnolang/gno/tests"
)

type runOptions struct {
Verbose bool `flag:"verbose" help:"verbose"`
RootDir string `flag:"root-dir" help:"clone location of github.com/gnolang/gno (gnodev tries to guess it)"`
// Timeout time.Duration `flag:"timeout" help:"max execution time"`
// VM Options
// UseNativeLibs bool // experimental, but could be useful for advanced developer needs
}

var defaultRunOptions = runOptions{
Verbose: false,
RootDir: "",
}

func runApp(cmd *command.Command, args []string, iopts interface{}) error {
opts := iopts.(runOptions)
if len(args) == 0 {
cmd.ErrPrintfln("Usage: run [flags] file.gno [file2.gno...]")
return errors.New("invalid args")
}

if opts.RootDir == "" {
opts.RootDir = guessRootDir()
}

fnames := args

return runRun(opts.RootDir, opts.Verbose, fnames)
}

func runRun(rootDir string, verbose bool, fnames []string) error {
stdin := os.Stdin
stdout := os.Stdout
stderr := os.Stderr

// init store and machine
testStore := tests.TestStore(rootDir, "", stdin, stdout, stderr, tests.ImportModeStdlibsOnly)
if verbose {
testStore.SetLogStoreOps(true)
}
m := gno.NewMachineWithOptions(gno.MachineOptions{
PkgPath: "main",
Output: stdout,
Store: testStore,
})

// read files
files := make([]*gno.FileNode, len(fnames))
for i, fname := range fnames {
files[i] = gno.MustReadFile(fname)
}

// run files
m.RunFiles(files...)
m.RunMain()

return nil
}

0 comments on commit 51c410d

Please sign in to comment.