command

package
v0.0.0-...-1327151 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package command provides a common structure for building command line programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackgroundContext

func BackgroundContext(log *zap.Logger) context.Context

BackgroundContext returns a context suitable for a command-line tool or service.

func Logger

func Logger() (*zap.Logger, error)

Logger initializes a logger suitable for command-line applications.

func Run

func Run(m MainStatus)

func RunError

func RunError(m MainError)

Types

type Base

type Base struct {
	Log *zap.Logger
}

Base is a base for all subcommands.

func NewBase

func NewBase(l *zap.Logger) Base

NewBase builds a new base command for the named tool.

func (Base) CheckClose

func (b Base) CheckClose(statusp *subcommands.ExitStatus, c io.Closer)

CheckClose closes c. On error it logs and writes to the status pointer. Intended for deferred Close() calls.

func (Base) Error

func (b Base) Error(err error) subcommands.ExitStatus

Error logs err and returns a failing exit code.

func (Base) Fail

func (b Base) Fail(format string, args ...interface{}) subcommands.ExitStatus

Fail logs an error message and returns a failing exit code.

func (Base) SetFlags

func (Base) SetFlags(f *flag.FlagSet)

SetFlags is a stub implementation of the SetFlags methods that does nothing.

func (Base) Status

func (b Base) Status(err error) subcommands.ExitStatus

Status fails if the provided error is non-nil, and returns success otherwise.

func (Base) UsageError

func (b Base) UsageError(format string, args ...interface{}) subcommands.ExitStatus

UsageError logs a usage error and returns a suitable exit code.

type MainError

type MainError func(context.Context, *zap.Logger) error

MainError is an entry point returning an error.

type MainStatus

type MainStatus func(context.Context, *zap.Logger) int

MainStatus is an entry point returnint an exit status.

Jump to

Keyboard shortcuts

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