Documentation ¶
Overview ¶
Package commandline contains common utilities for use across clis
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LogLevel = cli.StringFlag{ Name: "log-level", Usage: fmt.Sprintf("set the log level for the application to one of %s", LogLevelOptions()), Value: zapcore.WarnLevel.String(), DefaultText: "", }
LogLevel sets the log level for the node.
Functions ¶
func GenerateShellCommand ¶
func GenerateShellCommand(shellCommands []*cli.Command) *cli.Command
GenerateShellCommand generates the shell command with a list of commands that the shell should take. TODO: this needs a more comprehensive test suite.
func IsValidLogLevel ¶
IsValidLogLevel determines if a log level is valid.
func LogLevelOptions ¶
func LogLevelOptions() (res string)
LogLevelOptions generates log level options and returns them as a string.
func SetLogLevel ¶
func SetLogLevel(c *cli.Context)
SetLogLevel parses the cli context and sets the global log level accordingly. Note: for this to work the log level has to be set in the command.
Example ¶
package main import ( "fmt" "github.com/ipfs/go-log" "github.com/synapsecns/sanguine/core/commandline" "github.com/urfave/cli/v2" "go.uber.org/zap/zapcore" "os" ) var logger = log.Logger("synapse-logger-example") func main() { app := cli.NewApp() app.Commands = cli.Commands{ { Name: "test", Description: "I'm a test command", Flags: []cli.Flag{ &commandline.LogLevel, }, Action: func(c *cli.Context) error { commandline.SetLogLevel(c) logger.Debug("I won't be shown if level is set to warn") logger.Warn("I will be shown if level is set to warn") return nil }, }, } fmt.Printf("running ./example %s --%s %s", app.Commands[0].Name, commandline.LogLevel.Name, zapcore.WarnLevel.String()) err := app.Run([]string{os.Args[0], app.Commands[0].Name, commandline.LogLevel.Name, zapcore.WarnLevel.String()}) if err != nil { panic(err) } }
Output: running ./example test --log-level warn
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.