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.
This commit is contained in:
Roman Khimov 2019-10-19 23:58:45 +03:00
parent d46d679f36
commit dafd385f57
5 changed files with 20 additions and 22 deletions

View file

@ -17,12 +17,10 @@ func main() {
ctl.Version = config.Version ctl.Version = config.Version
ctl.Usage = "Official Go client for Neo" ctl.Usage = "Official Go client for Neo"
ctl.Commands = []cli.Command{ ctl.Commands = append(ctl.Commands, server.NewCommands()...)
server.NewCommand(), ctl.Commands = append(ctl.Commands, smartcontract.NewCommands()...)
smartcontract.NewCommand(), ctl.Commands = append(ctl.Commands, wallet.NewCommands()...)
wallet.NewCommand(), ctl.Commands = append(ctl.Commands, vm.NewCommands()...)
vm.NewCommand(),
}
if err := ctl.Run(os.Args); err != nil { if err := ctl.Run(os.Args); err != nil {
panic(err) panic(err)

View file

@ -16,9 +16,9 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// NewCommand creates a new Node command. // NewCommands returns 'node' command.
func NewCommand() cli.Command { func NewCommands() []cli.Command {
return cli.Command{ return []cli.Command{{
Name: "node", Name: "node",
Usage: "start a NEO node", Usage: "start a NEO node",
Action: startServer, Action: startServer,
@ -29,7 +29,7 @@ func NewCommand() cli.Command {
cli.BoolFlag{Name: "testnet, t"}, cli.BoolFlag{Name: "testnet, t"},
cli.BoolFlag{Name: "debug, d"}, cli.BoolFlag{Name: "debug, d"},
}, },
} }}
} }
func newGraceContext() context.Context { func newGraceContext() context.Context {

View file

@ -35,9 +35,9 @@ func Main(op string, args []interface{}) {
}` }`
) )
// NewCommand returns a new contract command. // NewCommands returns 'contract' command.
func NewCommand() cli.Command { func NewCommands() []cli.Command {
return cli.Command{ return []cli.Command{{
Name: "contract", Name: "contract",
Usage: "compile - debug - deploy smart contracts", Usage: "compile - debug - deploy smart contracts",
Subcommands: []cli.Command{ Subcommands: []cli.Command{
@ -98,7 +98,7 @@ func NewCommand() cli.Command {
}, },
}, },
}, },
} }}
} }
// initSmartContract initializes a given directory with some boiler plate code. // initSmartContract initializes a given directory with some boiler plate code.

View file

@ -9,9 +9,9 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// NewCommand creates a new VM command. // NewCommands returns 'vm' command.
func NewCommand() cli.Command { func NewCommands() []cli.Command {
return cli.Command{ return []cli.Command{{
Name: "vm", Name: "vm",
Usage: "start the virtual machine", Usage: "start the virtual machine",
Action: startVMPrompt, Action: startVMPrompt,
@ -31,7 +31,7 @@ func NewCommand() cli.Command {
}, },
}, },
}, },
} }}
} }
func startVMPrompt(ctx *cli.Context) error { func startVMPrompt(ctx *cli.Context) error {

View file

@ -16,9 +16,9 @@ var (
errPhraseMismatch = errors.New("the entered pass-phrases do not match. Maybe you have misspelled them") errPhraseMismatch = errors.New("the entered pass-phrases do not match. Maybe you have misspelled them")
) )
// NewCommand creates a new Wallet command. // NewCommands returns 'wallet' command.
func NewCommand() cli.Command { func NewCommands() []cli.Command {
return cli.Command{ return []cli.Command{{
Name: "wallet", Name: "wallet",
Usage: "create, open and manage a NEO wallet", Usage: "create, open and manage a NEO wallet",
Subcommands: []cli.Command{ Subcommands: []cli.Command{
@ -49,7 +49,7 @@ func NewCommand() cli.Command {
}, },
}, },
}, },
} }}
} }
func openWallet(ctx *cli.Context) error { func openWallet(ctx *cli.Context) error {