cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DebugLogConfig is used to generate a *zap.Logger for debug mode.
	DebugLogConfig = func() zap.Config {
		cfg := zap.NewProductionConfig()
		cfg.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
		cfg.DisableStacktrace = true
		return cfg
	}()
	// VerboseLogConfig is used to generate a *zap.Logger for verbose mode.
	VerboseLogConfig = func() zap.Config {
		cfg := zap.NewDevelopmentConfig()
		cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
		cfg.Level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
		cfg.EncoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
			enc.AppendString(t.Local().Format("2006-01-02 15:04:05 MST"))
		}
		return cfg
	}()
)

Functions

func AddLoggingFlags

func AddLoggingFlags(cmd *cobra.Command)

AddLoggingFlags sets "--debug" and "--verbose" flags to the given *cobra.Command instance.

func Close

func Close()

Close closes cli utilities.

func Debug

func Debug()

Debug sets a debug logger in global.

func IsDebug

func IsDebug() bool

IsDebug returns true if a debug logger is used.

func IsVerbose

func IsVerbose() bool

IsVerbose returns true if a verbose logger is used.

func NewVersionCommand

func NewVersionCommand(io IO, cfg Build) *cobra.Command

NewVersionCommand create a new cobra.Command to print the version information.

func Verbose

func Verbose()

Verbose sets a verbose logger in global.

Types

type Build

type Build struct {
	AppName   string
	Version   string
	Revision  string
	BuildDate string
}

Build is a container for the application build information.

type IO

type IO interface {
	In() io.Reader
	Out() io.Writer
	Err() io.Writer
}

IO contains an input reader, an output writer and an error writer.

func Stdio

func Stdio() IO

Stdio returns a standard IO object.

type IOContainer

type IOContainer struct {
	InR  io.Reader
	OutW io.Writer
	ErrW io.Writer
}

IOContainer is a basic implementation of the IO interface.

func (*IOContainer) Err

func (i *IOContainer) Err() io.Writer

func (*IOContainer) In

func (i *IOContainer) In() io.Reader

func (*IOContainer) Out

func (i *IOContainer) Out() io.Writer

type LoggingMode

type LoggingMode int

LoggingMode represents a logging configuration specification.

const (
	LoggingNop LoggingMode = iota
	LoggingVerbose
	LoggingDebug
)

LoggingMode values

func Logging

func Logging() LoggingMode

Logging returns a current logging mode.

type Path

type Path string

Path represents a filepath in filesystem.

func (Path) Join

func (p Path) Join(elem ...string) Path

Join joins path elements to the path.

func (Path) String

func (p Path) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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