Documentation
¶
Index ¶
- Variables
- func BindOutputFormat(persistentFlags *pflag.FlagSet) 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) error
- 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 PrintNDJSON(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
- type OutputFormat
- type TemplateFailureError
- type TreeError
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidOutputFormat = errors.New("invalid output format")
ErrInvalidOutputFormat is returned when the provided output format is unsupported.
Functions ¶
func BindOutputFormat ¶
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) error
PrintByFormat prints data to stdout according to the provided output format. Falls back to JSON when format is unrecognized.
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 PrintNDJSON ¶
PrintNDJSON prints one JSON object per line. If v is a slice, it prints each element on its own line. Otherwise, it prints v.
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.
Types ¶
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatJSON OutputFormat = "json" OutputFormatYAML OutputFormat = "yaml" OutputFormatNDJSON OutputFormat = "ndjson" OutputFormatTree OutputFormat = "tree" )
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
}