clib

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 12 Imported by: 23

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(cfg Build) *cobra.Command

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

func SetIO added in v0.3.0

func SetIO(c *cobra.Command, io *IO)

SetIO set an IO to *cobra.Command.

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 struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

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

func GetIO added in v0.3.0

func GetIO(c *cobra.Command) *IO

GetIO extract an IO object from *cobra.Command.

func NewBufferedIO added in v0.3.0

func NewBufferedIO() *IO

func NewIO added in v0.3.0

func NewIO(inR io.Reader, outW io.Writer, errW io.Writer) *IO

func Stdio

func Stdio() *IO

Stdio returns a standard IO object.

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

Jump to

Keyboard shortcuts

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