netmaker/netclient/cli_options/cmds.go

102 lines
2.3 KiB
Go
Raw Normal View History

2021-12-09 05:52:32 +08:00
package cli_options
import (
"errors"
"github.com/gravitl/netmaker/netclient/command"
"github.com/gravitl/netmaker/netclient/config"
"github.com/urfave/cli/v2"
)
// GetCommands - return commands that CLI uses
func GetCommands(cliFlags []cli.Flag) []*cli.Command {
return []*cli.Command{
{
Name: "join",
Usage: "Join a Netmaker network.",
Flags: cliFlags,
Action: func(c *cli.Context) error {
cfg, pvtKey, err := config.GetCLIConfig(c)
if err != nil {
return err
}
if cfg.Network == "all" {
2022-01-02 23:30:07 +08:00
err = errors.New("no network provided")
2021-12-09 05:52:32 +08:00
return err
}
if cfg.Server.GRPCAddress == "" {
2022-01-02 23:30:07 +08:00
err = errors.New("no server address provided")
2021-12-09 05:52:32 +08:00
return err
}
err = command.Join(cfg, pvtKey)
return err
},
},
{
Name: "leave",
Usage: "Leave a Netmaker network.",
Flags: cliFlags,
// the action, or code that will be executed when
// we execute our `ns` command
Action: func(c *cli.Context) error {
cfg, _, err := config.GetCLIConfig(c)
if err != nil {
return err
}
2022-02-21 07:09:32 +08:00
err = command.Leave(cfg, c.String("force") == "yes")
2021-12-09 05:52:32 +08:00
return err
},
},
{
Name: "pull",
Usage: "Pull latest configuration and peers from server.",
Flags: cliFlags,
// the action, or code that will be executed when
// we execute our `ns` command
Action: func(c *cli.Context) error {
cfg, _, err := config.GetCLIConfig(c)
if err != nil {
return err
}
err = command.Pull(cfg)
return err
},
},
{
Name: "list",
Usage: "Get list of networks.",
Flags: cliFlags,
// the action, or code that will be executed when
// we execute our `ns` command
Action: func(c *cli.Context) error {
cfg, _, err := config.GetCLIConfig(c)
if err != nil {
return err
}
err = command.List(cfg)
return err
},
},
{
Name: "uninstall",
Usage: "Uninstall the netclient system service.",
Flags: cliFlags,
// the action, or code that will be executed when
// we execute our `ns` command
Action: func(c *cli.Context) error {
err := command.Uninstall()
return err
},
},
2022-01-03 00:02:59 +08:00
{
Name: "daemon",
Usage: "run netclient as daemon",
Flags: cliFlags,
Action: func(c *cli.Context) error {
err := command.Daemon()
return err
},
},
2021-12-09 05:52:32 +08:00
}
}