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

feat: utilize ffcli (CLI refactor) #497

Merged
merged 50 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6819d5a
Add basic ff/cli support for the gnotxport command
zivkovicmilos Jan 31, 2023
cc47032
Add a wrapper for ffcli
zivkovicmilos Jan 31, 2023
7a475ff
Apply the minor ffcli refactor to the gnoland command
zivkovicmilos Jan 31, 2023
bc2233e
Remove unused param
zivkovicmilos Jan 31, 2023
4a5ab3d
Standardize parse and run error format
zivkovicmilos Feb 1, 2023
2d1127e
Remove explicit blank command name setting
zivkovicmilos Feb 1, 2023
05db95c
Remove the Command name param
zivkovicmilos Feb 1, 2023
797f8df
Compact the export flag registration
zivkovicmilos Feb 1, 2023
962860d
Slightly adjust exec method setting
zivkovicmilos Feb 8, 2023
634c233
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 8, 2023
7a4d641
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 10, 2023
c93c665
Sort using goimports
zivkovicmilos Feb 10, 2023
3d333e1
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 13, 2023
7dfdb3a
Make sure genproto uses the new ffcli wrapper
zivkovicmilos Feb 13, 2023
aafb402
Use ffcli for gnofaucet
zivkovicmilos Feb 14, 2023
b56a282
Use ffcli for goscan
zivkovicmilos Feb 14, 2023
2cf4116
Use ffcli for gnodev
zivkovicmilos Feb 14, 2023
859e575
Resolve gnodev tests
zivkovicmilos Feb 14, 2023
e6b5ccd
Resolve failing gnodev test
zivkovicmilos Feb 14, 2023
6c365f2
Resolve example test runs
zivkovicmilos Feb 14, 2023
64435c4
Add ffcli support for gnokey add
zivkovicmilos Feb 16, 2023
aa9c80c
Add ffcli support for gnokey delete
zivkovicmilos Feb 16, 2023
6b722c6
Add ffcli support for gnokey generate
zivkovicmilos Feb 16, 2023
005d6a5
Add ffcli support for gnokey export / import
zivkovicmilos Feb 16, 2023
36ad20e
Add ffcli support for gnokey list
zivkovicmilos Feb 16, 2023
740c745
Add ffcli support for gnokey sign
zivkovicmilos Feb 17, 2023
92625e2
Add ffcli support for gnokey verify
zivkovicmilos Feb 17, 2023
2d2bf08
Add ffcli support for gnokey query
zivkovicmilos Feb 17, 2023
9c01939
Add ffcli support for gnokey broadcast
zivkovicmilos Feb 17, 2023
d29a354
Add ffcli support for gnokey maketx addpkg
zivkovicmilos Feb 17, 2023
eef1792
Add ffcli support for gnokey maketx send
zivkovicmilos Feb 17, 2023
127d18a
Add ffcli support for gnokey maketx call
zivkovicmilos Feb 17, 2023
f3aeaed
Skip failing test for now
zivkovicmilos Feb 17, 2023
a4ada47
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 20, 2023
01932d0
Remove unused params
zivkovicmilos Feb 20, 2023
52a7da5
Add finer command IO control
zivkovicmilos Feb 20, 2023
3cb8d01
Resolve failing gnodev tests
zivkovicmilos Feb 20, 2023
75690ec
Standardize command io
zivkovicmilos Feb 20, 2023
c592778
Standardize command io
zivkovicmilos Feb 20, 2023
d9ba917
Clean up command utils
zivkovicmilos Feb 20, 2023
393f35d
Swap IO prints
zivkovicmilos Feb 20, 2023
a9dc36c
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 20, 2023
25f398a
Update Makefile to have correct flag order
zivkovicmilos Feb 20, 2023
99ab05c
Update Makefile to have correct flag order
zivkovicmilos Feb 20, 2023
96f4de5
Update workflow flag position
zivkovicmilos Feb 20, 2023
9df7403
Move the gnokey command structure into the client package
zivkovicmilos Feb 21, 2023
ea1807a
Add empty config to commands that don't need one
zivkovicmilos Feb 21, 2023
29cbbc9
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 23, 2023
2b9f4b1
Merge branch 'master' into feature/improve-cli
zivkovicmilos Feb 27, 2023
ef49c21
Merge branch 'master' into feature/improve-cli
zivkovicmilos Mar 1, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
goversion: ["1.19.x", "1.20.x"]
goversion: [ "1.19.x", "1.20.x" ]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -31,5 +31,5 @@ jobs:
# TODO: implement --allow-all-imports
#- run: gnodev precompile ./stdlibs --verbose --allow-all-imports
#- run: gnodev precompile ./tests --verbose --allow-all-imports
- run: go run ./cmd/gnodev precompile ./examples --verbose
- run: go run ./cmd/gnodev build ./examples --verbose
- run: go run ./cmd/gnodev precompile --verbose ./examples
- run: go run ./cmd/gnodev build --verbose ./examples
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ clean:
rm -rf build

examples.precompile: install_gnodev
go run ./cmd/gnodev precompile ./examples --verbose
go run ./cmd/gnodev precompile --verbose ./examples

examples.build: install_gnodev examples.precompile
go run ./cmd/gnodev build ./examples --verbose
go run ./cmd/gnodev build --verbose ./examples

########################################
# Formatting, linting.
Expand Down Expand Up @@ -146,10 +146,10 @@ test.packages2:
go test tests/*.go -v -run "TestPackages/bytes" --timeout 30m

test.examples:
go run ./cmd/gnodev test ./examples --verbose
go run ./cmd/gnodev test --verbose ./examples

test.examples.sync:
go run ./cmd/gnodev test ./examples --verbose --update-golden-tests
go run ./cmd/gnodev test --verbose --update-golden-tests ./examples

# Code gen
stringer:
Expand Down
10 changes: 5 additions & 5 deletions pkgs/crypto/keys/client/options.go → cmd/common/common.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package client
moul marked this conversation as resolved.
Show resolved Hide resolved
package common

import (
"fmt"
"os"
)

type BaseOptions struct {
Home string `flag:"home" help:"home directory"`
Remote string `flag:"remote" help:"remote node URL (default 127.0.0.1:26657)"`
Quiet bool `flag:"quiet" help:"for parsing output"`
InsecurePasswordStdin bool `flag:"insecure-password-stdin" help:"WARNING! take password from stdin"`
Home string
Remote string
Quiet bool
InsecurePasswordStdin bool
}

var DefaultBaseOptions = BaseOptions{
Expand Down
25 changes: 25 additions & 0 deletions cmd/genproto/genproto.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package main

import (
"context"
"fmt"
"os"

"github.com/gnolang/gno/pkgs/amino"
"github.com/gnolang/gno/pkgs/amino/genproto"
"github.com/gnolang/gno/pkgs/commands"

// TODO: move these out.
abci "github.com/gnolang/gno/pkgs/bft/abci/types"
Expand All @@ -24,6 +29,22 @@ import (
)

func main() {
cmd := commands.NewCommand(
commands.Metadata{
LongHelp: "Generates proto bindings for Amino packages",
},
nil,
moul marked this conversation as resolved.
Show resolved Hide resolved
execGen,
)

if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v", err)

os.Exit(1)
}
}

func execGen(_ context.Context, _ []string) error {
pkgs := []*amino.Package{
bitarray.Package,
merkle.Package,
Expand All @@ -42,12 +63,16 @@ func main() {
vm.Package,
gno.Package,
}

for _, pkg := range pkgs {
genproto.WriteProto3Schema(pkg)
genproto.WriteProtoBindings(pkg)
genproto.MakeProtoFolder(pkg, "proto")
}

for _, pkg := range pkgs {
genproto.RunProtoc(pkg, "proto")
}

return nil
}
67 changes: 50 additions & 17 deletions cmd/gnodev/build.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
package main

import (
"context"
"flag"
"fmt"
"os"

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

type buildOptions struct {
Verbose bool `flag:"verbose" help:"verbose"`
GoBinary string `flag:"go-binary" help:"go binary to use for building"`
type buildCfg struct {
verbose bool
goBinary string
}

var defaultBuildOptions = buildOptions{
Verbose: false,
GoBinary: "go",
var defaultBuildOptions = &buildCfg{
verbose: false,
goBinary: "go",
}

func buildApp(cmd *command.Command, args []string, iopts interface{}) error {
opts := iopts.(buildOptions)
func newBuildCmd(io *commands.IO) *commands.Command {
cfg := &buildCfg{}

return commands.NewCommand(
commands.Metadata{
Name: "build",
ShortUsage: "build [flags] <package>",
ShortHelp: "Builds the specified gno package",
},
cfg,
func(_ context.Context, args []string) error {
return execBuild(cfg, args, io)
},
)
}

func (c *buildCfg) RegisterFlags(fs *flag.FlagSet) {
fs.BoolVar(
&c.verbose,
"verbose",
defaultBuildOptions.verbose,
"verbose output when building",
)

fs.StringVar(
&c.goBinary,
"go-binary",
defaultBuildOptions.goBinary,
"go binary to use for building",
)
}

func execBuild(cfg *buildCfg, args []string, io *commands.IO) error {
if len(args) < 1 {
cmd.ErrPrintfln("Usage: build [build flags] [packages]")
return errors.New("invalid args")
return flag.ErrHelp
}

paths, err := gnoPackagesFromArgs(args)
Expand All @@ -33,23 +64,25 @@ func buildApp(cmd *command.Command, args []string, iopts interface{}) error {

errCount := 0
for _, pkgPath := range paths {
err = goBuildFileOrPkg(pkgPath, opts)
err = goBuildFileOrPkg(pkgPath, cfg)
if err != nil {
err = fmt.Errorf("%s: build pkg: %w", pkgPath, err)
cmd.ErrPrintfln("%s", err.Error())
io.ErrPrintfln("%s\n", err.Error())

errCount++
}
}

if errCount > 0 {
return fmt.Errorf("%d go build errors", errCount)
}

return nil
}

func goBuildFileOrPkg(fileOrPkg string, opts buildOptions) error {
verbose := opts.Verbose
goBinary := opts.GoBinary
func goBuildFileOrPkg(fileOrPkg string, cfg *buildCfg) error {
verbose := cfg.verbose
goBinary := cfg.goBinary

if verbose {
fmt.Fprintf(os.Stderr, "%s\n", fileOrPkg)
Expand Down
8 changes: 2 additions & 6 deletions cmd/gnodev/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import "testing"
func TestBuildApp(t *testing.T) {
tc := []testMainCase{
{
args: []string{"build"},
errShouldBe: "invalid args",
stderrShouldBe: "Usage: build [build flags] [packages]\n",
}, {
args: []string{"build", "--help"},
stdoutShouldContain: "# buildOptions options\n-",
args: []string{"build"},
errShouldBe: "flag: help requested",
},

// {args: []string{"build", "..."}, stdoutShouldContain: "..."},
Expand Down
126 changes: 40 additions & 86 deletions cmd/gnodev/main.go
Original file line number Diff line number Diff line change
@@ -1,99 +1,53 @@
package main

import (
"context"
"fmt"
"os"

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

func main() {
cmd := command.NewStdCommand()
exec := os.Args[0]
args := os.Args[1:]
err := runMain(cmd, exec, args)
if err != nil {
cmd.ErrPrintfln("%s", err.Error())
// cmd.ErrPrintfln("%#v", err)
os.Exit(1)
}
}
cmd := newGnodevCmd(commands.NewDefaultIO())

type (
AppItem = command.AppItem
AppList = command.AppList
)

var mainApps AppList = []AppItem{
{
App: runApp,
Name: "run",
Desc: "run a Gno file",
Defaults: defaultRunOptions,
},
{
App: buildApp,
Name: "build",
Desc: "build a gno package",
Defaults: defaultBuildOptions,
},
{
App: modApp,
Name: "mod",
Desc: "manage gno.mod",
Defaults: defaultModFlags,
},
{
App: precompileApp,
Name: "precompile",
Desc: "precompile .gno to .go",
Defaults: defaultPrecompileFlags,
},
{
App: testApp,
Name: "test",
Desc: "test a gno package",
Defaults: defaultTestOptions,
},
{
App: replApp,
Name: "repl",
Desc: "start a GnoVM REPL",
Defaults: defaultReplOptions,
},
if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v", err)

// fmt -- gofmt
// clean
// graph
// vendor -- download deps from the chain in vendor/
// list -- list packages
// render -- call render()?
// publish/release
// generate
// doc -- godoc
// "vm" -- starts an in-memory chain that can be interacted with?
// bug -- start a bug report
// version -- show gnodev, golang versions
}

func runMain(cmd *command.Command, exec string, args []string) error {
// show help message.
if len(args) == 0 || args[0] == "help" || args[0] == "--help" {
cmd.Println("available subcommands:")
for _, appItem := range mainApps {
cmd.Printf(" %s - %s\n", appItem.Name, appItem.Desc)
}
return nil
}

// switch on first argument.
for _, appItem := range mainApps {
if appItem.Name == args[0] {
err := cmd.Run(appItem.App, args[1:], appItem.Defaults)
return err // done
}
os.Exit(1)
}
}

// unknown app command!
return errors.New("unknown command " + args[0])
func newGnodevCmd(io *commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "<subcommand> [flags] [<arg>...]",
LongHelp: "Runs the gno development toolkit",
},
nil,
commands.HelpExec,
)

cmd.AddSubCommands(
newRunCmd(io),
newBuildCmd(io),
newPrecompileCmd(io),
newTestCmd(io),
newReplCmd(),
newModCmd(),
// fmt -- gofmt
// clean
// graph
// vendor -- download deps from the chain in vendor/
// list -- list packages
// render -- call render()?
// publish/release
// generate
// doc -- godoc
// "vm" -- starts an in-memory chain that can be interacted with?
// bug -- start a bug report
// version -- show gnodev, golang versions
)

return cmd
}
Loading