cmd

package module
v0.0.0-...-23b4f86 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Apache-2.0 Imports: 16 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FormatQuiet      format = "quiet"
	FormatTable      format = "table"
	FormatJSON       format = "json"
	FormatJSONPretty format = "json-pretty"

	FlagQuiet  = "quiet"
	FlagFormat = "format"

	None = "<none>"
)

Variables

View Source
var (
	// ErrNilDependency is returned if a dependency is missing.
	ErrNilDependency = errors.New("a dependency was expected to be defined but is nil. Please open an issue with the stack trace")
	// ErrNoPrintButFail is returned to detect a failure state that was already reported to the user in some way
	ErrNoPrintButFail = errors.New("this error should never be printed")
)

Functions

func AskForConfirmation

func AskForConfirmation(s string, stdin io.Reader, stdout io.Writer) bool

AskForConfirmation asks for confirmation with the question string s and reads the answer pass nil to use os.Stdin and os.Stdout

func CheckResponse

func CheckResponse(err error, expectedStatusCode int, response *http.Response)

CheckResponse fatals if err is nil or the response.StatusCode does not match the expectedStatusCode

func EnvVarExamplesHelpMessage

func EnvVarExamplesHelpMessage(name string) string

EnvVarExamplesHelpMessage returns a string containing documentation on how to use environment variables.

func ExactArgs

func ExactArgs(cmd *cobra.Command, args []string, l int)

ExactArgs fatals if args does not equal l.

func Exec

func Exec(_ *testing.T, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)

Exec runs the provided cobra command with the given reader as STD_IN and the given args. Returns STD_OUT, STD_ERR and the error from the execution.

func ExecExpectedErr

func ExecExpectedErr(t *testing.T, cmd *cobra.Command, args ...string) string

ExecExpectedErr is a helper that assumes a failing run from Exec returning ErrNoPrintButFail Returns STD_ERR.

func ExecNoErr

func ExecNoErr(t *testing.T, cmd *cobra.Command, args ...string) string

ExecNoErr is a helper that assumes a successful run from Exec. Returns STD_OUT.

func ExpectDependency

func ExpectDependency(logger *logrusx.Logger, dependencies ...interface{})

ExpectDependency expects every dependency to be not nil or it fatals.

func FailSilently

func FailSilently(cmd *cobra.Command) error

FailSilently is supposed to be used within a commands RunE function. It silences cobras error handling and returns the ErrNoPrintButFail error.

func Fatalf

func Fatalf(message string, args ...interface{})

Fatalf prints to os.Stderr and exists with code 1.

func FormatResponse

func FormatResponse(o interface{}) string

FormatResponse takes an object and prints a json.MarshalIdent version of it or fatals.

func MinArgs

func MinArgs(cmd *cobra.Command, args []string, min int)

MinArgs fatals if args does not satisfy min.

func Must

func Must(err error, message string, args ...interface{})

Must fatals with the optional message if err is not nil.

func PrintCollection

func PrintCollection(cmd *cobra.Command, collection OutputCollection)

func PrintErrors

func PrintErrors(cmd *cobra.Command, errs map[string]error)

func PrintRow

func PrintRow(cmd *cobra.Command, row OutputEntry)

func RangeArgs

func RangeArgs(cmd *cobra.Command, args []string, r []int)

RangeArgs fatals if args does not satisfy any of the lengths set in r.

func RegisterFormatFlags

func RegisterFormatFlags(flags *pflag.FlagSet)

func Version

func Version(gitTag, gitHash, buildTime *string) *cobra.Command

Version returns a *cobra.Command that handles the `version` command.

Types

type OutputCollection

type OutputCollection interface {
	OutputHeader
	Table() [][]string
	Interface() interface{}
	Len() int
}

type OutputEntry

type OutputEntry interface {
	OutputHeader
	Fields() []string
	Interface() interface{}
}

type OutputHeader

type OutputHeader interface {
	Header() []string
}

Jump to

Keyboard shortcuts

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