Documentation ¶
Overview ¶
Package cli contains helper functions related to flag parsing and logging.
Index ¶
- Variables
- func InitFileLogging(logFile string, logFileLevel int)
- func InitLogging(verbosity int)
- func ParseFlags(appname string, data interface{}, args []string) (*flags.Parser, []string, error)
- func ParseFlagsFromArgsOrDie(appname, version string, data interface{}, args []string) *flags.Parser
- func ParseFlagsOrDie(appname, version string, data interface{}) *flags.Parser
- type ByteSize
- type Duration
- type LogBackend
Constants ¶
This section is empty.
Variables ¶
var StdErrIsATerminal = terminal.IsTerminal(int(os.Stderr.Fd()))
var StripAnsi = regexp.MustCompile("\x1b[^m]+m")
Functions ¶
func InitFileLogging ¶
InitFileLogging initialises an optional logging backend to a file.
func ParseFlags ¶
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, version string, data interface{}, args []string) *flags.Parser
ParseFlagsFromArgsOrDie is similar to ParseFlagsOrDie but allows control over the flags passed.
func ParseFlagsOrDie ¶
func ParseFlagsOrDie(appname, version string, data interface{}) *flags.Parser
ParseFlagsOrDie, as the name suggests, parses the app's flags and dies if unsuccessful. Also dies if any unexpected arguments are passed.
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.
func (*ByteSize) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface
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 LogBackend ¶
type LogBackend struct { sync.Mutex // Protects access to LogMessages Rows, Cols, MaxRecords, InteractiveRows, MaxInteractiveRows int Output []string LogMessages *list.List Formatter logging.Formatter // TODO(pebers): seems a bit weird that we have to have this here, but it doesn't // contains filtered or unexported fields } // seem to be possible to retrieve the formatter from outside the package?
LogBackend is the backend we use for logging during the interactive console display.
func NewLogBackend ¶
func NewLogBackend(interactiveRows int) *LogBackend
NewLogBackend constructs a new logging backend.
func (*LogBackend) Deactivate ¶
func (backend *LogBackend) Deactivate()
Deactivate removes this backend as the currently active log backend.
func (*LogBackend) RecalcLines ¶
func (backend *LogBackend) RecalcLines()
func (*LogBackend) SetActive ¶
func (backend *LogBackend) SetActive()
SetActive sets this backend as the currently active log backend.