forked from ligato/vpp-agent
/
commands.go
63 lines (55 loc) · 1.48 KB
/
commands.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package commands
import (
"fmt"
"os"
"github.com/ligato/cn-infra/logging"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/ligato/vpp-agent/cmd/agentctl/cli"
)
var (
// RootName defines default name used for the root command.
RootName = "agentctl"
)
// NewAgentCli creates new AgentCli with opts and configures log output to error stream.
func NewAgentCli(opts ...cli.AgentCliOption) *cli.AgentCli {
agentCli, err := cli.NewAgentCli(opts...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
logrus.SetOutput(agentCli.Err())
logging.DefaultLogger.SetOutput(agentCli.Err())
return agentCli
}
// NewRootCommand is helper for default initialization process for root command.
// Returs cobra command which is ready to be executed.
func NewRootCommand(agentCli *cli.AgentCli) (*cobra.Command, error) {
root := NewRoot(agentCli)
cmd, err := root.PrepareCommand()
if err != nil {
return nil, err
}
if err := root.Initialize(); err != nil {
return nil, err
}
return cmd, nil
}
// NewRoot returns new Root using RootName for name.
func NewRoot(agentCli *cli.AgentCli) *Root {
return NewRootNamed(RootName, agentCli)
}
// AddBaseCommands adds all base commands to cmd.
func AddBaseCommands(cmd *cobra.Command, cli cli.Cli) {
cmd.AddCommand(
NewModelCommand(cli),
NewLogCommand(cli),
NewImportCommand(cli),
NewVppCommand(cli),
NewDumpCommand(cli),
NewKvdbCommand(cli),
NewGenerateCommand(cli),
NewStatusCommand(cli),
NewValuesCommand(cli),
)
}