Documentation
¶
Index ¶
- Constants
- Variables
- func AvailableOutputFormats() []string
- func BindOutputFormat(persistentFlags *pflag.FlagSet, defaultValue OutputFormat) error
- func CountItems(v any) int
- func ExitCode(err error) int
- func FormatShortTime(t time.Time) string
- func Int64String(v int64) string
- func PrintAppResponseMeta(st *styles.Styles, meta *responsemeta.ResponseMeta, verbose bool, colored bool)
- func PrintByFormat(data any, format OutputFormat, colored bool) cenclierrors.CencliError
- func PrintDataWithTemplate(templatePath string, colored bool, data any) cenclierrors.CencliError
- func PrintError(err error, cmd *cobra.Command)
- func PrintJSON(v any, colored bool) error
- func PrintTree(v any, colored bool) cenclierrors.CencliError
- func PrintYAML(v any, colored bool) error
- func Printf(w io.Writer, format string, a ...any)
- func Println(w io.Writer, a ...any)
- func StderrIsTTY() bool
- func StdoutIsTTY() bool
- func TruncateEnd(s string, max int) string
- func WriteNDJSONItem(w io.Writer, item any, colored bool) error
- type OutputFormat
- type TemplateFailureError
- type TreeError
Constants ¶
const (
OutputFormatFlagName = "output-format"
)
Variables ¶
var ErrInvalidOutputFormat = errors.New("invalid output format")
ErrInvalidOutputFormat is returned when the provided output format is unsupported.
Functions ¶
func AvailableOutputFormats ¶ added in v0.1.0
func AvailableOutputFormats() []string
func BindOutputFormat ¶
func BindOutputFormat(persistentFlags *pflag.FlagSet, defaultValue OutputFormat) error
func CountItems ¶
CountItems returns the number of items if v is a slice/array; otherwise 1.
func ExitCode ¶
ExitCode maps an error to a conventional CLI exit code. 0: success 2: usage/config/input error (print usage) 124: timeout 130: interrupted (canceled) 1: general error
func FormatShortTime ¶
FormatShortTime renders a timestamp in a compact, human-friendly format.
func Int64String ¶
Int64String returns the base-10 string representation of v.
func PrintAppResponseMeta ¶
func PrintAppResponseMeta(st *styles.Styles, meta *responsemeta.ResponseMeta, verbose bool, colored bool)
PrintAppResponseMeta renders application-level response metadata without leaking http.Request/Response. When verbose is true, sanitized headers are printed for debugging purposes, as well as the request URL.
func PrintByFormat ¶
func PrintByFormat(data any, format OutputFormat, colored bool) cenclierrors.CencliError
PrintByFormat prints data to stdout according to the provided output format. Falls back to JSON when format is unrecognized.
Note: NDJSON is not supported here - it requires streaming via WithStreamingOutput. Commands that support NDJSON must use OutputTypeStreaming and skip PrintData when streaming.
func PrintDataWithTemplate ¶
func PrintDataWithTemplate(templatePath string, colored bool, data any) cenclierrors.CencliError
PrintDataWithTemplate renders data through a template and writes the result to stdout. Callers must provide what kind of data needs to be rendered, so its correspoinding template can be used. Returns error if the template does not exist for the given entity, or the template fails to render.
func PrintError ¶
PrintError prints an error in a standardized format. Takes an optional cobra command to print usage information if the error should print usage.
func PrintJSON ¶
PrintJSON prints v as pretty JSON, optionally colored. Uses the standard library for marshaling (to support omitzero), then colorizes the output if requested.
func PrintTree ¶
func PrintTree(v any, colored bool) cenclierrors.CencliError
func StderrIsTTY ¶
func StderrIsTTY() bool
func StdoutIsTTY ¶
func StdoutIsTTY() bool
func TruncateEnd ¶
TruncateEnd returns s truncated to max characters with an ellipsis suffix if needed.
func WriteNDJSONItem ¶ added in v0.1.0
WriteNDJSONItem encodes a single item as NDJSON (one line of JSON) to the provided writer. This enables true streaming output where each item is written immediately. The item is encoded without pretty-printing (compact JSON on a single line). Uses the standard library for marshaling (to support omitzero), then colorizes the output if requested.
Types ¶
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatJSON OutputFormat = "json" OutputFormatYAML OutputFormat = "yaml" OutputFormatNDJSON OutputFormat = "ndjson" OutputFormatTree OutputFormat = "tree" OutputFormatShort OutputFormat = "short" OutputFormatTemplate OutputFormat = "template" )
func (OutputFormat) String ¶
func (o OutputFormat) String() string
func (*OutputFormat) UnmarshalText ¶
func (o *OutputFormat) UnmarshalText(text []byte) error
type TemplateFailureError ¶
type TemplateFailureError interface {
cenclierrors.CencliError
}
type TreeError ¶
type TreeError interface {
cenclierrors.CencliError
}