1package common
2
3import (
4	"github.com/sirupsen/logrus"
5	"github.com/urfave/cli"
6	clihelpers "gitlab.com/ayufan/golang-cli-helpers"
7)
8
9var commands []cli.Command
10
11type Commander interface {
12	Execute(c *cli.Context)
13}
14
15func RegisterCommand(command cli.Command) {
16	logrus.Debugln("Registering", command.Name, "command...")
17	commands = append(commands, command)
18}
19
20func RegisterCommand2(name, usage string, data Commander, flags ...cli.Flag) {
21	RegisterCommand(cli.Command{
22		Name:   name,
23		Usage:  usage,
24		Action: data.Execute,
25		Flags:  append(flags, clihelpers.GetFlagsFromStruct(data)...),
26	})
27}
28
29func GetCommands() []cli.Command {
30	return commands
31}
32