Documentation ¶
Overview ¶
Package output provides structured output for *cobra.Command. Formatted output is enabled by setting the --output=[json|yaml] flag.
Index ¶
- func DefaultYAML(cmd *cobra.Command, _ []string) error
- func Err(ctx context.Context) io.Writer
- func Execute(cmd *cobra.Command) (*cobra.Command, bool, error)
- func Info(ctx context.Context) io.Writer
- func Object(ctx context.Context, obj any, override bool)
- func Out(ctx context.Context) io.Writer
- func WantsFormatted(cmd *cobra.Command) bool
- func WantsStream(cmd *cobra.Command) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultYAML ¶ added in v2.9.0
DefaultYAML is a PersistentPRERunE function that will change the default output format to "yaml" for the command that invokes it.
func Err ¶ added in v2.9.0
Err returns an io.Writer that writes to the ErrOrStderr of the current *cobra.Command, or if no command is active, to the os.Stderr. If formatted output is requested, the output will be delayed until Execute is called.
func Execute ¶ added in v2.9.0
Execute will call ExecuteC on the given command, optionally print all formatted output, and return a boolean indicating if formatted output was printed. The result of the execution is provided in the second return value.
func Info ¶ added in v2.9.0
Info is similar to Out, but if formatted output is requested, the output will be discarded.
Info is primarily intended for messages that are not directly related to the command that executes, such as messages about starting up daemons or being connected to a context.
func Object ¶ added in v2.9.0
Object sets the object to be marshalled and printed on stdout when formatted output is requested using the `--output=<fmt>` flag. Otherwise, this function does nothing.
If override is set to true, then the formatted output will consist solely of the given object. There will be no "cmd", "stdout", or "stderr" tags.
The function will panic if data already has been written to the stdout of the command or if an Object already has been called.
func Out ¶ added in v2.9.0
Out returns an io.Writer that writes to the OutOrStdout of the current *cobra.Command, or if no command is active, to the os.Stdout. If formatted output is requested, the output will be delayed until Execute is called.
func WantsFormatted ¶ added in v2.9.0
WantsFormatted returns true if the value of the global `--output` flag is set to a valid format different from "default".
func WantsStream ¶ added in v2.11.0
WantsStream returns true if the value of the global `--output` flag is set to "json-stream".
Types ¶
This section is empty.