cli

package module
v3.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

go-cli-init

Wrapper handling initialisation of flags & logging libraries

Documentation

Overview

Package cli contains initialisation functions for go-flags and go-logging. It facilitates sharing them between several projects.

Index

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

func ParseFlagsFromArgsOrDie(appname string, data interface{}, args []string) string

ParseFlagsFromArgsOrDie is similar to ParseFlagsOrDie but allows control over the flags passed. It returns the active command if there is one.

func ParseFlagsOrDie

func ParseFlagsOrDie(appname string, data interface{}) string

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

func (b *ByteSize) UnmarshalFlag(in string) error

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

type Duration time.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

func (d *Duration) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

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.

const MaxVerbosity Verbosity = Verbosity(logging.DEBUG)

MaxVerbosity is the maximum verbosity we support.

const MinVerbosity Verbosity = Verbosity(logging.ERROR)

MinVerbosity is the maximum verbosity we support.

func (*Verbosity) UnmarshalFlag

func (v *Verbosity) UnmarshalFlag(in string) error

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL