Documentation ¶
Index ¶
- Constants
- Variables
- func AskForConfirmation(s string, stdin io.Reader, stdout io.Writer) bool
- func CheckResponse(err error, expectedStatusCode int, response *http.Response)
- func EnvVarExamplesHelpMessage(name string) string
- func ExactArgs(cmd *cobra.Command, args []string, l int)
- func Exec(_ *testing.T, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)
- func ExecExpectedErr(t *testing.T, cmd *cobra.Command, args ...string) string
- func ExecNoErr(t *testing.T, cmd *cobra.Command, args ...string) string
- func ExpectDependency(dependencies ...interface{})
- func FailSilently(cmd *cobra.Command) error
- func Fatalf(message string, args ...interface{})
- func FormatResponse(o interface{}) string
- func Generate(cmd *cobra.Command, args []string) error
- func MinArgs(cmd *cobra.Command, args []string, min int)
- func Must(err error, message string, args ...interface{})
- func MustGetBool(cmd *cobra.Command, name string) bool
- func MustGetDuration(cmd *cobra.Command, name string) time.Duration
- func MustGetInt(cmd *cobra.Command, name string) int
- func MustGetString(cmd *cobra.Command, name string) string
- func MustGetStringSlice(cmd *cobra.Command, name string) []string
- func PrintCollection(cmd *cobra.Command, collection OutputCollection)
- func PrintErrors(cmd *cobra.Command, errs map[string]error)
- func PrintRow(cmd *cobra.Command, row OutputEntry)
- func RangeArgs(cmd *cobra.Command, args []string, r []int)
- func RegisterFormatFlags(flags *pflag.FlagSet)
- func Version(gitTag, gitHash, buildTime *string) *cobra.Command
- type OutputCollection
- type OutputEntry
- type OutputHeader
Constants ¶
const ( FormatQuiet format = "quiet" FormatTable format = "table" FormatJSON format = "json" FormatJSONPretty format = "json-pretty" FlagQuiet = "quiet" FlagFormat = "format" None = "<none>" )
Variables ¶
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 ¶
asks for confirmation with the question string s and reads the answer pass nil to use os.Stdin and os.Stdout
func CheckResponse ¶
CheckResponse fatals if err is nil or the response.StatusCode does not match the expectedStatusCode
func EnvVarExamplesHelpMessage ¶
EnvVarExamplesHelpMessage returns a string containing documentation on how to use environment variables.
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 ¶
ExecExpectedErr is a helper that assumes a failing run from Exec returning ErrNoPrintButFail Returns STD_ERR.
func ExpectDependency ¶
func ExpectDependency(dependencies ...interface{})
ExpectDependency expects every dependency to be not nil or it fatals.
func FailSilently ¶
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 MustGetBool ¶
MustGetBool returns a bool flag or fatals if an error occurs.
func MustGetDuration ¶
MustGetDuration returns a time.Duration flag or fatals if an error occurs.
func MustGetInt ¶
MustGetInt returns a int flag or fatals if an error occurs.
func MustGetString ¶
MustGetString returns a string flag or fatals if an error occurs.
func MustGetStringSlice ¶
MustGetStringSlice returns a []string flag or fatals if an error occurs.
func PrintCollection ¶
func PrintCollection(cmd *cobra.Command, collection OutputCollection)
func PrintRow ¶
func PrintRow(cmd *cobra.Command, row OutputEntry)
func RegisterFormatFlags ¶
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
}