stdcli

package
v0.0.0-...-218c583 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Binary     string
	Commands   []cli.Command
	FileWriter func(filename string, data []byte, perm os.FileMode) error
	Exiter     func(code int)
	Runner     func(bin string, args ...string) error
	Querier    func(bin string, args ...string) ([]byte, error)
	Spinner    *spinner.Spinner
	Tagger     func() string
	HelpFlags  []string
)

Functions

func CheckEnv

func CheckEnv() error

CheckEnv validates that relevant envvars have acceptable values

func CliCheckEnv

func CliCheckEnv(c *cli.Context) error

CliCheckEnv takes cli.Context as an arg so it can be used as a BeforeFunc

func Debug

func Debug() bool

func Default

func Default(value, def string) string

func DirApp

func DirApp(c *cli.Context, wd string) (string, string, error)

If user specifies the app's name from command line, then use it; if not, try to read the app name from .convox/app otherwise use the current working directory's name

func Duration

func Duration(start, end time.Time) string

func EnsureOnlyFlags

func EnsureOnlyFlags(c *cli.Context, args []string)

EnsureOnlyFlags ensures that every element in the args slice starts with --

func Error

func Error(err error) error

func Errorf

func Errorf(format string, args ...interface{}) error

func FlagsToOptions

func FlagsToOptions(c *cli.Context, args []string) map[string]string

FlagsToOptions converts a list of '--key=value'/'--bool' strings to 'key: value, bool: true'-style map

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal tells you if a given file descriptor has a tty on the other side

func NeedArg

func NeedArg(c *cli.Context, count int)

NeedArg checks that we have received the expected number of arguments

func NeedHelp

func NeedHelp(c *cli.Context)

NeedHelp checks for help flags (-h, --help) and args (h, help).

func New

func New() *cli.App

func OK

func OK() (int, error)

func ParseOpts

func ParseOpts(args []string) map[string]string

func QOSEventSend

func QOSEventSend(system, id string, ep QOSEventProperties) error

QOSEventSend sends an internal CLI event to segment for quality-of-service purposes. If the event is an error it also sends the error to rollbar, then displays the error to the user and exits non-zero.

func Query

func Query(bin string, args ...string) ([]byte, error)

func ReadSetting

func ReadSetting(setting string) string

func RecoverFlag

func RecoverFlag(c *cli.Context, flagNames ...string) string

RecoverFlag allows us to capture things like --app FOO which would otherwise be discarded by urfave/cli if passed in position 0

func RegisterCommand

func RegisterCommand(cmd cli.Command)

func Run

func Run(bin string, args ...string) error

func Sprintf

func Sprintf(format string, args ...interface{}) string

func Startf

func Startf(format string, args ...interface{}) (int, error)

func Tag

func Tag() string

func Usage

func Usage(c *cli.Context)

Usage prints help for the current command and exits

func ValidatePreconditions

func ValidatePreconditions(preconditions ...cli.BeforeFunc) cli.BeforeFunc

ValidatePreconditions runs one or more cli.BeforeFuncs where called in Command.Before

func VersionPrinter

func VersionPrinter(printer func(*cli.Context))

func Wait

func Wait(status string) (int, error)

func Warn

func Warn(msg string) (int, error)

Warn prints a string in dark orange.

func Write

func Write(data []byte) (int, error)

func WriteSetting

func WriteSetting(setting, value string) error

func Writef

func Writef(format string, args ...interface{}) (int, error)

Types

type ErrorStdCli

type ErrorStdCli string

ErrorStdCli represents a generic stdcli error

func (ErrorStdCli) Error

func (e ErrorStdCli) Error() string

Error satisfies the error interface

type Info

type Info struct {
	Rows []InfoRow
}

func NewInfo

func NewInfo() *Info

func (*Info) Add

func (i *Info) Add(name, value string)

func (*Info) Print

func (i *Info) Print()

type InfoRow

type InfoRow struct {
	Name  string
	Value string
}

type QOSEventProperties

type QOSEventProperties struct {
	AppType         string
	Error           error
	Start           time.Time
	ValidationError error
}

type Renderer

type Renderer func(string) string

func RenderAttributes

func RenderAttributes(attrs ...int) Renderer

type Table

type Table struct {
	Headers []string
	Rows    [][]string
}

func NewTable

func NewTable(headers ...string) *Table

func (*Table) AddRow

func (t *Table) AddRow(values ...string)

func (*Table) Print

func (t *Table) Print()

type Writer

type Writer struct {
	Color  bool
	Stdout io.Writer
	Stderr io.Writer
	Tags   map[string]Renderer
}
var (
	DefaultWriter *Writer
)

func (*Writer) Error

func (w *Writer) Error(err error) error

func (*Writer) Errorf

func (w *Writer) Errorf(format string, args ...interface{}) error

func (*Writer) OK

func (w *Writer) OK() (int, error)

func (*Writer) Sprintf

func (w *Writer) Sprintf(format string, args ...interface{}) string

func (*Writer) Startf

func (w *Writer) Startf(format string, args ...interface{}) (int, error)

func (*Writer) Wait

func (w *Writer) Wait(status string) (int, error)

func (*Writer) Warn

func (w *Writer) Warn(status string) (int, error)

Warn wraps a string in <warn> tags

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

func (*Writer) Writef

func (w *Writer) Writef(format string, args ...interface{}) (int, error)

Jump to

Keyboard shortcuts

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