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(t testing.TB, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)
- func ExecBackgroundCtx(ctx context.Context, cmd *cobra.Command, stdIn io.Reader, ...) *errgroup.Group
- func ExecCtx(ctx context.Context, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)
- func ExecExpectedErr(t testing.TB, cmd *cobra.Command, args ...string) string
- func ExecExpectedErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string
- func ExecNoErr(t testing.TB, cmd *cobra.Command, args ...string) string
- func ExecNoErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string
- func ExpectDependency(logger *logrusx.Logger, dependencies ...interface{})
- func FailSilently(cmd *cobra.Command) error
- func Fatalf(message string, args ...interface{})
- func FormatResponse(o interface{}) string
- func MinArgs(cmd *cobra.Command, args []string, min int)
- func Must(err error, message string, args ...interface{})
- func PrintErrors(cmd *cobra.Command, errs map[string]error)
- func PrintJSONAble(cmd *cobra.Command, d interface{ ... })
- func PrintRow(cmd *cobra.Command, row TableRow)
- func PrintTable(cmd *cobra.Command, table Table)
- func RangeArgs(cmd *cobra.Command, args []string, r []int)
- func RegisterFormatFlags(flags *pflag.FlagSet)
- func RegisterJSONFormatFlags(flags *pflag.FlagSet)
- func RegisterNoiseFlags(flags *pflag.FlagSet)
- func Version(gitTag, gitHash, buildTime *string) *cobra.Command
- type CallbackWriter
- type CommandExecuter
- func (c *CommandExecuter) Exec(stdin io.Reader, args ...string) (string, string, error)
- func (c *CommandExecuter) ExecBackground(stdin io.Reader, stdOut, stdErr io.Writer, args ...string) *errgroup.Group
- func (c *CommandExecuter) ExecExpectedErr(t require.TestingT, args ...string) string
- func (c *CommandExecuter) ExecNoErr(t require.TestingT, args ...string) string
- type ConditionalPrinter
- func NewConditionalPrinter(w io.Writer, print bool) *ConditionalPrinter
- func NewLoudErrPrinter(cmd *cobra.Command) *ConditionalPrinter
- func NewLoudOutPrinter(cmd *cobra.Command) *ConditionalPrinter
- func NewLoudPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
- func NewQuietErrPrinter(cmd *cobra.Command) *ConditionalPrinter
- func NewQuietOutPrinter(cmd *cobra.Command) *ConditionalPrinter
- func NewQuietPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
- type Nil
- type Table
- type TableHeader
- type TableRow
Constants ¶
const ( FormatQuiet format = "quiet" FormatTable format = "table" FormatJSON format = "json" FormatJSONPretty format = "json-pretty" FormatDefault format = "default" FlagFormat = "format" None = "<none>" )
const (
FlagQuiet = "quiet"
)
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 ¶ added in v0.0.119
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 ¶ added in v0.0.154
func Exec(t testing.TB, 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 ExecBackgroundCtx ¶ added in v0.0.256
func ExecBackgroundCtx(ctx context.Context, cmd *cobra.Command, stdIn io.Reader, stdOut, stdErr io.Writer, args ...string) *errgroup.Group
ExecBackgroundCtx runs the cobra command in the background.
func ExecExpectedErr ¶ added in v0.0.154
ExecExpectedErr is a helper that assumes a failing run from Exec returning ErrNoPrintButFail Returns STD_ERR.
func ExecExpectedErrCtx ¶ added in v0.0.171
func ExecNoErr ¶ added in v0.0.154
ExecNoErr is a helper that assumes a successful run from Exec. Returns STD_OUT.
func ExecNoErrCtx ¶ added in v0.0.171
func ExpectDependency ¶ added in v0.0.37
ExpectDependency expects every dependency to be not nil or it fatals.
func FailSilently ¶ added in v0.0.152
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 PrintJSONAble ¶ added in v0.0.172
func PrintTable ¶ added in v0.0.172
func RangeArgs ¶ added in v0.0.6
RangeArgs fatals if args does not satisfy any of the lengths set in r.
func RegisterFormatFlags ¶ added in v0.0.152
func RegisterJSONFormatFlags ¶ added in v0.0.172
func RegisterNoiseFlags ¶ added in v0.0.173
Types ¶
type CallbackWriter ¶ added in v0.0.256
type CallbackWriter struct { Callbacks map[string]func([]byte) error // contains filtered or unexported fields }
CallbackWriter will execute each callback once the message is received. The full matched message is passed to the callback. An error returned from the callback is returned by Write.
func (*CallbackWriter) String ¶ added in v0.0.256
func (c *CallbackWriter) String() string
type CommandExecuter ¶ added in v0.0.171
type CommandExecuter struct { New func() *cobra.Command Ctx context.Context PersistentArgs []string }
func (*CommandExecuter) ExecBackground ¶ added in v0.0.256
func (*CommandExecuter) ExecExpectedErr ¶ added in v0.0.171
func (c *CommandExecuter) ExecExpectedErr(t require.TestingT, args ...string) string
type ConditionalPrinter ¶ added in v0.0.173
type ConditionalPrinter struct {
// contains filtered or unexported fields
}
func NewConditionalPrinter ¶ added in v0.0.173
func NewConditionalPrinter(w io.Writer, print bool) *ConditionalPrinter
func NewLoudErrPrinter ¶ added in v0.0.173
func NewLoudErrPrinter(cmd *cobra.Command) *ConditionalPrinter
NewLoudErrPrinter returns a ConditionalPrinter that only prints to cmd.ErrOrStderr when --quiet is not set
func NewLoudOutPrinter ¶ added in v0.0.173
func NewLoudOutPrinter(cmd *cobra.Command) *ConditionalPrinter
NewLoudOutPrinter returns a ConditionalPrinter that only prints to cmd.OutOrStdout when --quiet is not set
func NewLoudPrinter ¶ added in v0.0.173
func NewLoudPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
NewLoudPrinter returns a ConditionalPrinter that only prints to w when --quiet is not set
func NewQuietErrPrinter ¶ added in v0.0.173
func NewQuietErrPrinter(cmd *cobra.Command) *ConditionalPrinter
NewQuietErrPrinter returns a ConditionalPrinter that only prints to cmd.ErrOrStderr when --quiet is set
func NewQuietOutPrinter ¶ added in v0.0.173
func NewQuietOutPrinter(cmd *cobra.Command) *ConditionalPrinter
NewQuietOutPrinter returns a ConditionalPrinter that only prints to cmd.OutOrStdout when --quiet is set
func NewQuietPrinter ¶ added in v0.0.173
func NewQuietPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
NewQuietPrinter returns a ConditionalPrinter that only prints to w when --quiet is set
func (*ConditionalPrinter) Print ¶ added in v0.0.173
func (p *ConditionalPrinter) Print(a ...interface{}) (n int, err error)
func (*ConditionalPrinter) Printf ¶ added in v0.0.173
func (p *ConditionalPrinter) Printf(format string, a ...interface{}) (n int, err error)
func (*ConditionalPrinter) Println ¶ added in v0.0.173
func (p *ConditionalPrinter) Println(a ...interface{}) (n int, err error)
type Table ¶ added in v0.0.172
type Table interface { TableHeader Table() [][]string Interface() interface{} Len() int }
type TableHeader ¶ added in v0.0.172
type TableHeader interface {
Header() []string
}
type TableRow ¶ added in v0.0.172
type TableRow interface { TableHeader Columns() []string Interface() interface{} }