netmaker/netclient/cli_options/cmds.go

123 lines
2.7 KiB
Go
Raw Normal View History

2021-12-09 05:52:32 +08:00
package cli_options
import (
"github.com/gravitl/netmaker/logger"
2021-12-09 05:52:32 +08:00
"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 {
parseVerbosity(c)
2021-12-09 05:52:32 +08:00
cfg, pvtKey, err := config.GetCLIConfig(c)
if err != nil {
return err
}
2022-04-25 22:38:29 +08:00
err = command.Join(&cfg, pvtKey)
2021-12-09 05:52:32 +08:00
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 {
parseVerbosity(c)
2021-12-09 05:52:32 +08:00
cfg, _, err := config.GetCLIConfig(c)
if err != nil {
return err
}
err = command.Leave(&cfg)
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 {
parseVerbosity(c)
2021-12-09 05:52:32 +08:00
cfg, _, err := config.GetCLIConfig(c)
if err != nil {
return err
}
err = command.Pull(&cfg)
2021-12-09 05:52:32 +08:00
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 {
parseVerbosity(c)
2021-12-09 05:52:32 +08:00
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 {
parseVerbosity(c)
2021-12-09 05:52:32 +08:00
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 {
// set max verbosity for daemon regardless
logger.Verbosity = 4
2022-01-03 00:02:59 +08:00
err := command.Daemon()
return err
},
},
2022-06-24 02:06:26 +08:00
{
Name: "install",
Usage: "install binary and daemon",
Flags: cliFlags,
Action: func(c *cli.Context) error {
parseVerbosity(c)
return command.Install()
},
},
2021-12-09 05:52:32 +08:00
}
}
2022-03-24 23:32:58 +08:00
// == Private funcs ==
func parseVerbosity(c *cli.Context) {
2022-03-25 01:52:40 +08:00
if c.Bool("v") {
2022-03-24 23:32:58 +08:00
logger.Verbosity = 1
2022-03-25 01:52:40 +08:00
} else if c.Bool("vv") {
2022-03-24 23:32:58 +08:00
logger.Verbosity = 2
2022-03-25 01:52:40 +08:00
} else if c.Bool("vvv") {
2022-03-24 23:32:58 +08:00
logger.Verbosity = 3
} else if c.Bool("vvvv") {
logger.Verbosity = 4
2022-03-24 23:32:58 +08:00
}
}