forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: utilize ffcli (CLI refactor) (gnolang#497)
- Loading branch information
1 parent
d70f873
commit 3e44da4
Showing
67 changed files
with
2,923 additions
and
2,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
commands.NewEmptyConfig(), | ||
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 | ||
} |
Oops, something went wrong.