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.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)

View file

@ -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 {

View file

@ -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.

View file

@ -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 {

View file

@ -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 {