From dafd385f5743270545b278990af57b4dab6a316a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 19 Oct 2019 23:58:45 +0300 Subject: [PATCH] cli: extend NewCommand() to NewCommands() So that each module could now return an array of commands. It's gonna be used in the future to extend them. --- cli/main.go | 10 ++++------ cli/server/server.go | 8 ++++---- cli/smartcontract/smart_contract.go | 8 ++++---- cli/vm/vm.go | 8 ++++---- cli/wallet/wallet.go | 8 ++++---- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cli/main.go b/cli/main.go index e58aaf157..6e2817ac9 100644 --- a/cli/main.go +++ b/cli/main.go @@ -17,12 +17,10 @@ func main() { ctl.Version = config.Version ctl.Usage = "Official Go client for Neo" - ctl.Commands = []cli.Command{ - server.NewCommand(), - smartcontract.NewCommand(), - wallet.NewCommand(), - vm.NewCommand(), - } + ctl.Commands = append(ctl.Commands, server.NewCommands()...) + ctl.Commands = append(ctl.Commands, smartcontract.NewCommands()...) + ctl.Commands = append(ctl.Commands, wallet.NewCommands()...) + ctl.Commands = append(ctl.Commands, vm.NewCommands()...) if err := ctl.Run(os.Args); err != nil { panic(err) diff --git a/cli/server/server.go b/cli/server/server.go index 53eb68c43..fd60f7e3b 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -16,9 +16,9 @@ import ( "github.com/urfave/cli" ) -// NewCommand creates a new Node command. -func NewCommand() cli.Command { - return cli.Command{ +// NewCommands returns 'node' command. +func NewCommands() []cli.Command { + return []cli.Command{{ Name: "node", Usage: "start a NEO node", Action: startServer, @@ -29,7 +29,7 @@ func NewCommand() cli.Command { cli.BoolFlag{Name: "testnet, t"}, cli.BoolFlag{Name: "debug, d"}, }, - } + }} } func newGraceContext() context.Context { diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 4cd604e59..c967e42e7 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -35,9 +35,9 @@ func Main(op string, args []interface{}) { }` ) -// NewCommand returns a new contract command. -func NewCommand() cli.Command { - return cli.Command{ +// NewCommands returns 'contract' command. +func NewCommands() []cli.Command { + return []cli.Command{{ Name: "contract", Usage: "compile - debug - deploy smart contracts", Subcommands: []cli.Command{ @@ -98,7 +98,7 @@ func NewCommand() cli.Command { }, }, }, - } + }} } // initSmartContract initializes a given directory with some boiler plate code. diff --git a/cli/vm/vm.go b/cli/vm/vm.go index 35a8f92c2..7b3ac447b 100644 --- a/cli/vm/vm.go +++ b/cli/vm/vm.go @@ -9,9 +9,9 @@ import ( "github.com/urfave/cli" ) -// NewCommand creates a new VM command. -func NewCommand() cli.Command { - return cli.Command{ +// NewCommands returns 'vm' command. +func NewCommands() []cli.Command { + return []cli.Command{{ Name: "vm", Usage: "start the virtual machine", Action: startVMPrompt, @@ -31,7 +31,7 @@ func NewCommand() cli.Command { }, }, }, - } + }} } func startVMPrompt(ctx *cli.Context) error { diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index ce500e727..3091d74ed 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -16,9 +16,9 @@ var ( errPhraseMismatch = errors.New("the entered pass-phrases do not match. Maybe you have misspelled them") ) -// NewCommand creates a new Wallet command. -func NewCommand() cli.Command { - return cli.Command{ +// NewCommands returns 'wallet' command. +func NewCommands() []cli.Command { + return []cli.Command{{ Name: "wallet", Usage: "create, open and manage a NEO wallet", Subcommands: []cli.Command{ @@ -49,7 +49,7 @@ func NewCommand() cli.Command { }, }, }, - } + }} } func openWallet(ctx *cli.Context) error {