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 (
|
||||
"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
|
||||
},
|
||||
|
@@ -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.",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -27,8 +27,10 @@ import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version - version of the netclient
|
||||
var Version = "dev"
|
||||
Version = "dev"
|
||||
)
|
||||
|
||||
// MAX_NAME_LENGTH - maximum node name length
|
||||
const MAX_NAME_LENGTH = 62
|
||||
|
Reference in New Issue
Block a user