Documentation ¶
Overview ¶
Package cmdkit provides tools for implementing standard command patterns, such as fetch+print. Its use makes the code for most typical commands shorter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchAndPrint ¶
func FetchAndPrint(cmd *cobra.Command, path string, options *FetchAndPrintOptions)
FetchAndPrint consolidates the common sequence of fetching from the server and displaying the output of a command in the user-selected output format. If a human display format is selected, the function automatically converts the value to one of the supported formats (within limits); if it cannot be converted, YAML is displayed instead. If a cmd is not provided or it has no `output` flag, human output is assumed (table) If a human format is requested/assumed but no table is provided, it displays YAML If the object cannot be converted to the desired format, shows the object in Go's %+v format In addition, if the fetch API command fails, this function prints the error and exits with failure.
Types ¶
type FetchAndPrintOptions ¶
type FetchAndPrintOptions struct { Method *string // default "GET"; "GET", "POST" and "PATCH" are currently supported Headers map[string]string // http headers to send with the request Body any // body to send with the request (nil for no body) ResponseType *reflect.Type // structure type to parse response into (for schema validation & fields) (nil for none) IsCollection bool // set to true for GET to request a collection that may be paginated (see platform/api/collection.go) }