output

package
v2.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package output provides structured output for *cobra.Command. Formatted output is enabled by setting the --output=[json|yaml] flag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultYAML added in v2.9.0

func DefaultYAML(cmd *cobra.Command, _ []string) error

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

func Err(ctx context.Context) io.Writer

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

func Execute(cmd *cobra.Command) (*cobra.Command, bool, error)

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

func Info(ctx context.Context) io.Writer

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

func Object(ctx context.Context, obj any, override bool)

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

func Out(ctx context.Context) io.Writer

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

func WantsFormatted(cmd *cobra.Command) bool

WantsFormatted returns true if the value of the global `--output` flag is set to a valid format different from "default".

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL