mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-18 22:55:15 +08:00
reworked usage/description for netclient and added verbosity flags
This commit is contained in:
@@ -3,11 +3,22 @@ package cli_options
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/gravitl/netmaker/logger"
|
||||||
"github.com/gravitl/netmaker/netclient/command"
|
"github.com/gravitl/netmaker/netclient/command"
|
||||||
"github.com/gravitl/netmaker/netclient/config"
|
"github.com/gravitl/netmaker/netclient/config"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseVerbosity(c *cli.Context) {
|
||||||
|
if c.Bool("V") {
|
||||||
|
logger.Verbosity = 1
|
||||||
|
} else if c.Bool("VV") {
|
||||||
|
logger.Verbosity = 2
|
||||||
|
} else if c.Bool("VVV") {
|
||||||
|
logger.Verbosity = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetCommands - return commands that CLI uses
|
// GetCommands - return commands that CLI uses
|
||||||
func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
||||||
return []*cli.Command{
|
return []*cli.Command{
|
||||||
@@ -16,6 +27,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
Usage: "Join a Netmaker network.",
|
Usage: "Join a Netmaker network.",
|
||||||
Flags: cliFlags,
|
Flags: cliFlags,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
parseVerbosity(c)
|
||||||
cfg, pvtKey, err := config.GetCLIConfig(c)
|
cfg, pvtKey, err := config.GetCLIConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -39,6 +51,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
// the action, or code that will be executed when
|
// the action, or code that will be executed when
|
||||||
// we execute our `ns` command
|
// we execute our `ns` command
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
parseVerbosity(c)
|
||||||
cfg, _, err := config.GetCLIConfig(c)
|
cfg, _, err := config.GetCLIConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -54,6 +67,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
// the action, or code that will be executed when
|
// the action, or code that will be executed when
|
||||||
// we execute our `ns` command
|
// we execute our `ns` command
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
parseVerbosity(c)
|
||||||
cfg, _, err := config.GetCLIConfig(c)
|
cfg, _, err := config.GetCLIConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -69,6 +83,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
// the action, or code that will be executed when
|
// the action, or code that will be executed when
|
||||||
// we execute our `ns` command
|
// we execute our `ns` command
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
parseVerbosity(c)
|
||||||
cfg, _, err := config.GetCLIConfig(c)
|
cfg, _, err := config.GetCLIConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -84,6 +99,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
// the action, or code that will be executed when
|
// the action, or code that will be executed when
|
||||||
// we execute our `ns` command
|
// we execute our `ns` command
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
parseVerbosity(c)
|
||||||
err := command.Uninstall()
|
err := command.Uninstall()
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
@@ -93,6 +109,8 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command {
|
|||||||
Usage: "run netclient as daemon",
|
Usage: "run netclient as daemon",
|
||||||
Flags: cliFlags,
|
Flags: cliFlags,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
// set max verbosity for daemon regardless
|
||||||
|
logger.Verbosity = 3
|
||||||
err := command.Daemon()
|
err := command.Daemon()
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
@@ -204,5 +204,23 @@ func GetFlags(hostname string) []cli.Flag {
|
|||||||
Value: "no",
|
Value: "no",
|
||||||
Usage: "Allows to run the command with force, if otherwise prevented.",
|
Usage: "Allows to run the command with force, if otherwise prevented.",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "verbosity-level-1",
|
||||||
|
Aliases: []string{"V"},
|
||||||
|
Value: false,
|
||||||
|
Usage: "Netclient Verbosity level 1.",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "verbosity-level-2",
|
||||||
|
Aliases: []string{"VV"},
|
||||||
|
Value: false,
|
||||||
|
Usage: "Netclient Verbosity level 2.",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "verbosity-level-3",
|
||||||
|
Aliases: []string{"VVV"},
|
||||||
|
Value: false,
|
||||||
|
Usage: "Netclient Verbosity level 3.",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,6 @@ type ClientConfig struct {
|
|||||||
Daemon string `yaml:"daemon"`
|
Daemon string `yaml:"daemon"`
|
||||||
OperatingSystem string `yaml:"operatingsystem"`
|
OperatingSystem string `yaml:"operatingsystem"`
|
||||||
DebugOn bool `yaml:"debugon"`
|
DebugOn bool `yaml:"debugon"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfig - struct for dealing with the server information for a netclient
|
// ServerConfig - struct for dealing with the server information for a netclient
|
||||||
@@ -168,6 +167,9 @@ func ReplaceWithBackup(network string) error {
|
|||||||
// GetCLIConfig - gets the cli flags as a config
|
// GetCLIConfig - gets the cli flags as a config
|
||||||
func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
var cfg ClientConfig
|
var cfg ClientConfig
|
||||||
|
if c.String("version") != "" {
|
||||||
|
return cfg, c.String("version"), nil
|
||||||
|
}
|
||||||
if c.String("token") != "" {
|
if c.String("token") != "" {
|
||||||
tokenbytes, err := base64.StdEncoding.DecodeString(c.String("token"))
|
tokenbytes, err := base64.StdEncoding.DecodeString(c.String("token"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -17,13 +17,14 @@ var version = "dev"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Netclient CLI"
|
app.Name = "Netclient"
|
||||||
app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
|
|
||||||
app.Version = version
|
app.Version = version
|
||||||
ncutils.SetVersion(version)
|
ncutils.SetVersion(version)
|
||||||
|
|
||||||
cliFlags := cli_options.GetFlags(ncutils.GetHostname())
|
cliFlags := cli_options.GetFlags(ncutils.GetHostname())
|
||||||
app.Commands = cli_options.GetCommands(cliFlags[:])
|
app.Commands = cli_options.GetCommands(cliFlags[:])
|
||||||
|
app.Description = "Used to perform interactions with Netmaker server and set local WireGuard config."
|
||||||
|
app.Usage = "Netmaker's netclient agent and CLI."
|
||||||
|
app.UsageText = "netclient [global options] command [command options] [arguments...]. Adjust verbosity of given command with -V, -VV or -VVV (max)."
|
||||||
|
|
||||||
setGarbageCollection()
|
setGarbageCollection()
|
||||||
|
|
||||||
|
@@ -27,8 +27,10 @@ import (
|
|||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version - version of the netclient
|
var (
|
||||||
var Version = "dev"
|
// Version - version of the netclient
|
||||||
|
Version = "dev"
|
||||||
|
)
|
||||||
|
|
||||||
// MAX_NAME_LENGTH - maximum node name length
|
// MAX_NAME_LENGTH - maximum node name length
|
||||||
const MAX_NAME_LENGTH = 62
|
const MAX_NAME_LENGTH = 62
|
||||||
|
Reference in New Issue
Block a user