Documentation ¶
Index ¶
- Constants
- Variables
- func AddUsageTemplateFunc(name string, f interface{})
- func AskForConfirmation(s string, stdin io.Reader, stdout io.Writer) bool
- func AskScannerForConfirmation(s string, reader *bufio.Reader, stdout io.Writer) (bool, error)
- func AssertUsageTemplates(t require.TestingT, cmd *cobra.Command)
- func CheckResponse(err error, expectedStatusCode int, response *http.Response)
- func DisableUsageTemplating(cmds ...*cobra.Command)
- func EnableUsageTemplating(cmds ...*cobra.Command)
- 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 NewClient(cmd *cobra.Command) (*http.Client, *url.URL, error)
- func ParsePaginationArgs(cmd *cobra.Command, pageArg, perPageArg string) (page, perPage int64, err error)
- func ParseTokenPaginationArgs(cmd *cobra.Command) (page string, perPage int, err error)
- func PrintErrors(cmd *cobra.Command, errs map[string]error)
- func PrintJSONAble(cmd *cobra.Command, d interface{ ... })
- func PrintOpenAPIError(cmd *cobra.Command, err error) error
- 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 RegisterHTTPClientFlags(flags *pflag.FlagSet)
- func RegisterJSONFormatFlags(flags *pflag.FlagSet)
- func RegisterNoiseFlags(flags *pflag.FlagSet)
- func RegisterTokenPaginationFlags(cmd *cobra.Command) (pageSize int, pageToken string)
- func Remote(cmd *cobra.Command) (string, error)
- func RemoteURI(cmd *cobra.Command) (*url.URL, error)
- func TemplateCommandField(cmd *cobra.Command, field string) (string, error)
- func Version(gitTag, gitHash, buildTime *string) *cobra.Command
- func ZeroOrTwoArgs(cmd *cobra.Command, args []string) error
- 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 OutputIder
- type OutputIderCollection
- type PaginatedList
- type Table
- type TableHeader
- type TableRow
- type URL
Constants ¶
const ( FlagEndpoint = "endpoint" FlagSkipTLSVerify = "skip-tls-verify" FlagHeaders = "http-header" )
const ( FlagPageSize = "page-size" FlagPageToken = "page-token" )
const ( FormatQuiet format = "quiet" FormatTable format = "table" FormatJSON format = "json" FormatJSONPath format = "jsonpath" FormatJSONPointer format = "jsonpointer" FormatJSONPretty format = "json-pretty" FormatYAML format = "yaml" FormatDefault format = "default" FlagFormat = "format" None = "<none>" )
const (
FlagQuiet = "quiet"
)
Variables ¶
var ( // ErrNilDependency is returned if a dependency is missing. ErrNilDependency = fmt.Errorf("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 = fmt.Errorf("this error should never be printed") )
Functions ¶
func AddUsageTemplateFunc ¶ added in v0.0.480
func AddUsageTemplateFunc(name string, f interface{})
AddUsageTemplateFunc adds a template function to the usage template.
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 AskScannerForConfirmation ¶ added in v0.0.359
func AssertUsageTemplates ¶ added in v0.0.480
AssertUsageTemplates asserts that the usage string of the commands are properly templated.
func CheckResponse ¶
CheckResponse fatals if err is nil or the response.StatusCode does not match the expectedStatusCode Deprecated: do not use this function in commands, as it makes it impossible to test them. Instead, return the error.
func DisableUsageTemplating ¶ added in v0.0.478
DisableUsageTemplating resets the commands usage template to the default. This can be used to undo the effects of EnableUsageTemplating, specifically for a subcommand.
func EnableUsageTemplating ¶ added in v0.0.478
EnableUsageTemplating enables gotemplates for usage strings, i.e. cmd.Short, cmd.Long, and cmd.Example. The data for the template is the command itself. Especially useful are `.Root.Name` and `.CommandPath`. This will be inherited by all subcommands, so enabling it on the root command is sufficient.
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. Deprecated: do not use this function in commands, as it makes it impossible to test them. Instead, return the error.
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. Deprecated: do not use this function in commands, as it makes it impossible to test them. Instead, return the error.
func FormatResponse ¶
func FormatResponse(o interface{}) string
FormatResponse takes an object and prints a json.MarshalIdent version of it or fatals. Deprecated: do not use this function in commands, as it makes it impossible to test them. Instead, return the error.
func Must ¶
Must fatals with the optional message if err is not nil. Deprecated: do not use this function in commands, as it makes it impossible to test them. Instead, return the error.
func ParsePaginationArgs ¶ added in v0.0.425
func ParsePaginationArgs(cmd *cobra.Command, pageArg, perPageArg string) (page, perPage int64, err error)
ParsePaginationArgs parses pagination arguments from the command line.
func ParseTokenPaginationArgs ¶ added in v0.0.428
ParseTokenPaginationArgs parses token-based pagination arguments from the command line.
func PrintJSONAble ¶ added in v0.0.172
func PrintOpenAPIError ¶ added in v0.0.386
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 RegisterHTTPClientFlags ¶ added in v0.0.430
RegisterHTTPClientFlags registers HTTP client configuration flags.
func RegisterJSONFormatFlags ¶ added in v0.0.172
func RegisterNoiseFlags ¶ added in v0.0.173
func RegisterTokenPaginationFlags ¶ added in v0.0.428
func TemplateCommandField ¶ added in v0.0.573
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 OutputIder ¶ added in v0.0.424
type OutputIder string
OutputIder outputs an ID
func (OutputIder) Columns ¶ added in v0.0.424
func (i OutputIder) Columns() []string
func (OutputIder) Header ¶ added in v0.0.424
func (OutputIder) Header() []string
func (OutputIder) Interface ¶ added in v0.0.424
func (i OutputIder) Interface() interface{}
type OutputIderCollection ¶ added in v0.0.424
type OutputIderCollection struct {
Items []OutputIder
}
OutputIderCollection outputs a list of IDs
func (OutputIderCollection) Header ¶ added in v0.0.424
func (OutputIderCollection) Header() []string
func (OutputIderCollection) Interface ¶ added in v0.0.424
func (c OutputIderCollection) Interface() interface{}
func (OutputIderCollection) Len ¶ added in v0.0.424
func (c OutputIderCollection) Len() int
func (OutputIderCollection) Table ¶ added in v0.0.424
func (c OutputIderCollection) Table() [][]string
type PaginatedList ¶ added in v0.0.428
type PaginatedList struct { Collection interface { Table IDs() []string } `json:"-"` Items []interface{} `json:"items"` NextPageToken string `json:"next_page_token"` IsLastPage bool `json:"is_last_page"` }
func (*PaginatedList) Header ¶ added in v0.0.428
func (r *PaginatedList) Header() []string
func (*PaginatedList) IDs ¶ added in v0.0.428
func (r *PaginatedList) IDs() []string
func (*PaginatedList) Interface ¶ added in v0.0.428
func (r *PaginatedList) Interface() interface{}
func (*PaginatedList) Len ¶ added in v0.0.428
func (r *PaginatedList) Len() int
func (*PaginatedList) Table ¶ added in v0.0.428
func (r *PaginatedList) Table() [][]string
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{} }