Documentation ¶
Overview ¶
Package cli contains initialisation functions for go-flags and go-logging. It facilitates sharing them between several projects.
Index ¶
- func ActiveCommand(command *flags.Command) string
- func MustGetLogger() *logging.Logger
- func MustGetLoggerNamed(name string) *logging.Logger
- func ParseFlags(appname string, data interface{}, args []string, opts flags.Options, ...) (*flags.Parser, []string, error)
- func ParseFlagsFromArgsOrDie(appname string, data interface{}, args []string) string
- func ParseFlagsOrDie(appname string, data interface{}) string
- type ByteSize
- type CompletionHandler
- type Duration
- type LogLevelInfo
- func InitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string) (LogLevelInfo, error)
- func InitLogging(verbosity Verbosity) LogLevelInfo
- func InitStructuredLogging(stderrVerbosity, fileVerbosity Verbosity, filename string, structured bool) (LogLevelInfo, error)
- func MustInitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string) LogLevelInfo
- func MustInitStructuredLogging(stderrVerbosity, fileVerbosity Verbosity, filename string, structured bool) LogLevelInfo
- type Verbosity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActiveCommand ¶
func ActiveCommand(command *flags.Command) string
ActiveCommand returns the name of the currently active command.
func MustGetLogger ¶
func MustGetLogger() *logging.Logger
MustGetLogger is a wrapper around go-logging's function of the same name. It automatically determines a logger name. The logger is registered and will be returned by ModuleLevels().
func MustGetLoggerNamed ¶
func MustGetLoggerNamed(name string) *logging.Logger
MustGetLoggerNamed is like MustGetLogger but lets the caller choose the name.
func ParseFlags ¶
func ParseFlags(appname string, data interface{}, args []string, opts flags.Options, completionHandler CompletionHandler) (*flags.Parser, []string, error)
ParseFlags parses the app's flags and returns the parser, any extra arguments, and any error encountered. It may exit if certain options are encountered (eg. --help).
func ParseFlagsFromArgsOrDie ¶
ParseFlagsFromArgsOrDie is similar to ParseFlagsOrDie but allows control over the flags passed. It returns the active command if there is one.
func ParseFlagsOrDie ¶
ParseFlagsOrDie parses the app's flags and dies if unsuccessful. Also dies if any unexpected arguments are passed. It returns the active command if there is one.
Types ¶
type ByteSize ¶
type ByteSize uint64
A ByteSize is used for flags that represent some quantity of bytes that can be passed as human-readable quantities (eg. "10G").
func (*ByteSize) UnmarshalFlag ¶
UnmarshalFlag implements the flags.Unmarshaler interface.
type CompletionHandler ¶
type CompletionHandler func(parser *flags.Parser, items []flags.Completion)
A CompletionHandler is the type of function that our flags library uses to handle completions.
type Duration ¶
A Duration is used for flags that represent a time duration; it's just a wrapper around time.Duration that implements the flags.Unmarshaler and encoding.TextUnmarshaler interfaces.
func (*Duration) UnmarshalFlag ¶
UnmarshalFlag implements the flags.Unmarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface
type LogLevelInfo ¶
type LogLevelInfo interface { // ModuleLevels returns the level of all loggers retrieved by MustGetLogger(). ModuleLevels() map[string]logging.Level // SetLevel modifies the level of a specific logger. SetLevel(level logging.Level, module string) }
A LogLevelInfo describes and can modify levels of the set of registered loggers.
func InitFileLogging ¶
func InitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string) (LogLevelInfo, error)
InitFileLogging initialises logging backends, both to stderr and to a file. If the file path is empty then it will be ignored.
func InitLogging ¶
func InitLogging(verbosity Verbosity) LogLevelInfo
InitLogging initialises logging backends.
func InitStructuredLogging ¶ added in v3.1.0
func InitStructuredLogging(stderrVerbosity, fileVerbosity Verbosity, filename string, structured bool) (LogLevelInfo, error)
InitStructuredLogging is like InitFileLogging but allows specifying whether the output should be structured as JSON.
func MustInitFileLogging ¶
func MustInitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string) LogLevelInfo
MustInitFileLogging is like InitFileLogging but dies on any errors.
func MustInitStructuredLogging ¶ added in v3.1.0
func MustInitStructuredLogging(stderrVerbosity, fileVerbosity Verbosity, filename string, structured bool) LogLevelInfo
MustInitStructuredLogging is like InitStructuredLogging but dies on any errors.
type Verbosity ¶
type Verbosity logging.Level
A Verbosity is used as a flag to define logging verbosity.
MaxVerbosity is the maximum verbosity we support.
MinVerbosity is the maximum verbosity we support.
func (*Verbosity) UnmarshalFlag ¶
UnmarshalFlag implements flag parsing. It accepts input in three forms: As an integer level, -v 4 (where -v 1 == warning & error only) As a named level, -v debug As a series of flags, -vvv (but note that bare -v does *not* work)