diff --git a/netclient/cli_options/cmds.go b/netclient/cli_options/cmds.go index 26314e2b..1a556d83 100644 --- a/netclient/cli_options/cmds.go +++ b/netclient/cli_options/cmds.go @@ -3,11 +3,22 @@ package cli_options import ( "errors" + "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/netclient/command" "github.com/gravitl/netmaker/netclient/config" "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 func GetCommands(cliFlags []cli.Flag) []*cli.Command { return []*cli.Command{ @@ -16,6 +27,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { Usage: "Join a Netmaker network.", Flags: cliFlags, Action: func(c *cli.Context) error { + parseVerbosity(c) cfg, pvtKey, err := config.GetCLIConfig(c) if err != nil { return err @@ -39,6 +51,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { // the action, or code that will be executed when // we execute our `ns` command Action: func(c *cli.Context) error { + parseVerbosity(c) cfg, _, err := config.GetCLIConfig(c) if err != nil { return err @@ -54,6 +67,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { // the action, or code that will be executed when // we execute our `ns` command Action: func(c *cli.Context) error { + parseVerbosity(c) cfg, _, err := config.GetCLIConfig(c) if err != nil { return err @@ -69,6 +83,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { // the action, or code that will be executed when // we execute our `ns` command Action: func(c *cli.Context) error { + parseVerbosity(c) cfg, _, err := config.GetCLIConfig(c) if err != nil { return err @@ -84,6 +99,7 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { // the action, or code that will be executed when // we execute our `ns` command Action: func(c *cli.Context) error { + parseVerbosity(c) err := command.Uninstall() return err }, @@ -93,6 +109,8 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { Usage: "run netclient as daemon", Flags: cliFlags, Action: func(c *cli.Context) error { + // set max verbosity for daemon regardless + logger.Verbosity = 3 err := command.Daemon() return err }, diff --git a/netclient/cli_options/flags.go b/netclient/cli_options/flags.go index 5ac99ab9..081caf4c 100644 --- a/netclient/cli_options/flags.go +++ b/netclient/cli_options/flags.go @@ -204,5 +204,23 @@ func GetFlags(hostname string) []cli.Flag { Value: "no", 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.", + }, } } diff --git a/netclient/config/config.go b/netclient/config/config.go index 40ed3cf9..9c290b23 100644 --- a/netclient/config/config.go +++ b/netclient/config/config.go @@ -25,7 +25,6 @@ type ClientConfig struct { Daemon string `yaml:"daemon"` OperatingSystem string `yaml:"operatingsystem"` DebugOn bool `yaml:"debugon"` - } // 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 func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) { var cfg ClientConfig + if c.String("version") != "" { + return cfg, c.String("version"), nil + } if c.String("token") != "" { tokenbytes, err := base64.StdEncoding.DecodeString(c.String("token")) if err != nil { diff --git a/netclient/main.go b/netclient/main.go index 54bc3538..f4b92a8a 100644 --- a/netclient/main.go +++ b/netclient/main.go @@ -17,13 +17,14 @@ var version = "dev" func main() { app := cli.NewApp() - app.Name = "Netclient CLI" - app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config." + app.Name = "Netclient" app.Version = version ncutils.SetVersion(version) - cliFlags := cli_options.GetFlags(ncutils.GetHostname()) 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() diff --git a/netclient/ncutils/netclientutils.go b/netclient/ncutils/netclientutils.go index f7815c58..c37198ac 100644 --- a/netclient/ncutils/netclientutils.go +++ b/netclient/ncutils/netclientutils.go @@ -27,8 +27,10 @@ import ( "google.golang.org/grpc/credentials" ) -// Version - version of the netclient -var Version = "dev" +var ( + // Version - version of the netclient + Version = "dev" +) // MAX_NAME_LENGTH - maximum node name length const MAX_NAME_LENGTH = 62