summaryrefslogtreecommitdiff
path: root/common/command.go
blob: 5c04dfa377407d97e3a615aa2e2791d9b60fdd70 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package common

import (
	"github.com/sirupsen/logrus"
	"github.com/urfave/cli"
	"gitlab.com/ayufan/golang-cli-helpers"
)

var commands []cli.Command

type Commander interface {
	Execute(c *cli.Context)
}

func RegisterCommand(command cli.Command) {
	logrus.Debugln("Registering", command.Name, "command...")
	commands = append(commands, command)
}

func RegisterCommand2(name, usage string, data Commander, flags ...cli.Flag) {
	RegisterCommand(cli.Command{
		Name:   name,
		Usage:  usage,
		Action: data.Execute,
		Flags:  append(flags, clihelpers.GetFlagsFromStruct(data)...),
	})
}

func GetCommands() []cli.Command {
	return commands
}