cobra

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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

func Emit(cmd *cobra.Command, resp output.Response) error

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 EmitError

func EmitError(cmd *cobra.Command, command string, err error) error

EmitError builds an error envelope for command and emits it via Emit.

func Format

func Format(cmd *cobra.Command) output.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

func IsJSONOutput(cmd *cobra.Command) bool

IsJSONOutput reports whether the --output flag on cmd is "json".

func NewRenderer

func NewRenderer(cmd *cobra.Command, opts ...output.Option) *output.Renderer

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

func RegisterOutputFlag(cmd *cobra.Command)

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.

Jump to

Keyboard shortcuts

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