cli

package
v8.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2017 License: Apache-2.0 Imports: 21 Imported by: 90

Documentation

Overview

Package cli contains helper functions related to flag parsing and logging.

Index

Constants

This section is empty.

Variables

View Source
var StdErrIsATerminal = terminal.IsTerminal(int(os.Stderr.Fd()))
View Source
var StdOutIsATerminal = terminal.IsTerminal(int(os.Stdout.Fd()))
View Source
var StripAnsi = regexp.MustCompile("\x1b[^m]+m")

Functions

func Fprintf

func Fprintf(w io.Writer, msg string, args ...interface{})

Fprintf implements essentially fmt.Fprintf with replacements of some ANSI sequences, e.g. ${BOLD_RED} -> \x1bwhatever.

func InitFileLogging

func InitFileLogging(logFile string, logFileLevel int)

InitFileLogging initialises an optional logging backend to a file.

func InitLogging

func InitLogging(verbosity int)

InitLogging initialises logging backends.

func NewProgressReader

func NewProgressReader(reader io.Reader, total string) io.ReadCloser

NewProgressReader returns a new progress bar reader.

func ParseFlags

func ParseFlags(appname string, data interface{}, args []string) (*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, 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.

func Printf

func Printf(msg string, args ...interface{})

Printf is a convenience wrapper to Fprintf that always writes to stderr.

func WindowSize

func WindowSize() (int, int)

WindowSize finds and returns the size of the console window as (rows, columns)

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.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

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 (duration *Duration) UnmarshalText(text []byte) error

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.

type URL

type URL string

A URL is used for flags or config fields that represent a URL. It's just a string because it's more convenient that way; we haven't needed them as a net.URL so far.

func (*URL) String

func (u *URL) String() string

String implements the fmt.Stringer interface

func (*URL) UnmarshalFlag

func (u *URL) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type Version

type Version struct {
	semver.Version
	IsGTE bool
}

A Version is an extension to semver.Version extending it with the ability to recognise >= prefixes.

func (*Version) Semver

func (v *Version) Semver() semver.Version

Semver converts a Version to a semver.Version

func (Version) String

func (v Version) String() string

String implements the fmt.Stringer interface

func (*Version) UnmarshalFlag

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

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Version) UnmarshalText

func (v *Version) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

Jump to

Keyboard shortcuts

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