Documentation
¶
Overview ¶
Package cobra binds gitlab.com/phpboyscout/go/output to spf13/cobra commands.
It is a deliberately thin, opt-in integration: it reads the --output flag and the command's writer off a *cobra.Command and hands them to the framework-free core. Importing the core (gitlab.com/phpboyscout/go/output) never pulls cobra into the dependency graph; only importing this subpackage does.
Index ¶
- Constants
- func Emit(cmd *cobra.Command, resp output.Response) error
- func EmitError(cmd *cobra.Command, command string, err error) error
- func Format(cmd *cobra.Command) output.Format
- func IsJSONOutput(cmd *cobra.Command) bool
- func NewRenderer(cmd *cobra.Command, opts ...output.Option) *output.Renderer
- func RegisterOutputFlag(cmd *cobra.Command)
Constants ¶
const OutputFlag = "output"
OutputFlag is the name of the persistent flag this package reads and, via RegisterOutputFlag, defines.
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
Emit writes resp as a JSON envelope to cmd.OutOrStdout() when --output is "json"; it is a no-op otherwise. It is sugar for NewRenderer(cmd).Emit(resp).
func Format ¶
Format reads the --output flag off cmd and maps it to an output.Format, defaulting to output.FormatText when the flag is absent or unrecognised.
func IsJSONOutput ¶
IsJSONOutput reports whether the --output flag on cmd is "json".
func NewRenderer ¶
NewRenderer builds an output.Renderer from cmd: its writer is cmd.OutOrStdout() and its format is the --output flag (Format). Additional opts are applied last, so a caller may override the writer or supply a theme.
func RegisterOutputFlag ¶
RegisterOutputFlag adds a persistent --output flag to cmd with a consistent definition: default "text" and a usage string listing every supported format. Downstream CLIs call this on their root command so the flag is defined the same way everywhere.
Types ¶
This section is empty.