go.ligato.io/vpp-agent/v3@v3.5.0/cmd/agentctl/commands/commands.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/spf13/cobra"
     9  	"go.ligato.io/cn-infra/v2/logging"
    10  
    11  	"go.ligato.io/vpp-agent/v3/cmd/agentctl/cli"
    12  )
    13  
    14  var (
    15  	// RootName defines default name used for the root command.
    16  	RootName = "agentctl"
    17  )
    18  
    19  // NewAgentCli creates new AgentCli with opts and configures log output to error stream.
    20  func NewAgentCli(opts ...cli.AgentCliOption) *cli.AgentCli {
    21  	agentCli, err := cli.NewAgentCli(opts...)
    22  	if err != nil {
    23  		fmt.Fprintln(os.Stderr, err)
    24  		os.Exit(1)
    25  	}
    26  	logrus.SetOutput(agentCli.Err())
    27  	logging.DefaultLogger.SetOutput(agentCli.Err())
    28  	return agentCli
    29  }
    30  
    31  // NewRootCommand is helper for default initialization process for root command.
    32  // Returs cobra command which is ready to be executed.
    33  func NewRootCommand(agentCli *cli.AgentCli) (*cobra.Command, error) {
    34  	root := NewRoot(agentCli)
    35  	cmd, err := root.PrepareCommand()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  	if err := root.Initialize(); err != nil {
    40  		return nil, err
    41  	}
    42  	return cmd, nil
    43  }
    44  
    45  // NewRoot returns new Root using RootName for name.
    46  func NewRoot(agentCli *cli.AgentCli) *Root {
    47  	return NewRootNamed(RootName, agentCli)
    48  }
    49  
    50  // AddBaseCommands adds all base commands to cmd.
    51  func AddBaseCommands(cmd *cobra.Command, cli cli.Cli) {
    52  	cmd.AddCommand(
    53  		NewConfigCommand(cli),
    54  		newModelsCommand(cli),
    55  		NewModelCommand(cli),
    56  		NewLogCommand(cli),
    57  		NewImportCommand(cli),
    58  		NewVppCommand(cli),
    59  		NewDumpCommand(cli),
    60  		NewKvdbCommand(cli),
    61  		NewGenerateCommand(cli),
    62  		NewStatusCommand(cli),
    63  		NewValuesCommand(cli),
    64  		NewServiceCommand(cli),
    65  		NewMetricsCommand(cli),
    66  		NewReportCommand(cli),
    67  	)
    68  }