Merge pull request #960 from gravitl/feature_v0.12.2_client_verbosity

reworked usage/description for netclient and added verbosity flags
This commit is contained in:
dcarns 2022-03-25 09:11:34 -04:00 committed by GitHub
commit a6b1c6a8cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View file

@ -6,6 +6,9 @@ import (
"strings"
)
// Verbosity - current logging verbosity level (optionally set)
var Verbosity = 0
// MakeString - makes a string using golang string builder
func MakeString(delimeter string, message ...string) string {
var builder strings.Builder
@ -19,6 +22,9 @@ func MakeString(delimeter string, message ...string) string {
}
func getVerbose() int32 {
if Verbosity >= 1 && Verbosity <= 3 {
return int32(Verbosity)
}
level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
if err != nil || level < 0 {
level = 0

View file

@ -3,6 +3,7 @@ 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"
@ -16,6 +17,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 +41,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 +57,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 +73,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 +89,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,9 +99,23 @@ 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
},
},
}
}
// == Private funcs ==
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
}
}

View file

@ -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.",
},
}
}

View file

@ -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

View file

@ -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()