cli

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: Apache-2.0 Imports: 11 Imported by: 24

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 InitFileLogging added in v1.1.0

func InitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string) 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)

InitLogging initialises logging backends.

func MustInitFileLogging added in v1.1.0

func MustInitFileLogging(stderrVerbosity, fileVerbosity Verbosity, filename string)

MustInitFileLogging is like InitFileLogging but dies on any errors.

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 added in v1.3.0

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 added in v1.3.0

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 added in v1.2.0

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 added in v1.2.0

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

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Duration) UnmarshalText added in v1.2.0

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

UnmarshalText implements the encoding.TextUnmarshaler interface

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