cprint

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelInfo    = "info"
	LevelSuccess = "success"
	LevelWarning = "warning"
	LevelError   = "error"
	LevelVerbose = "verbose"
)

Message levels recorded in the JSON payload.

View Source
const FormatJSON = "json"

FormatJSON selects structured JSON output. Callers set it via SetFormat on a CPrinter. Consumers wrapping the CLI (e.g. the deploy-action GitHub wrapper) rely on this contract to parse results.

Variables

This section is empty.

Functions

func Error

func Error(cmd *cobra.Command, err error, verbose bool)

Standalone functions

func GreenPrint

func GreenPrint(message string)

func Info

func Info(message string)

func OrganizationInfo

func OrganizationInfo(orgID string, verbose bool)

func Print

func Print(message string)

func PrintDetail

func PrintDetail(label, value string)

func PrintHeader

func PrintHeader(message string)

func PrintNorm

func PrintNorm(message string)

func Prompt

func Prompt(message string, verbose bool)

func Success

func Success(message string)

func Warning

func Warning(message string)

func YellowPrint

func YellowPrint(message string)

Types

type CPrinter added in v0.12.6

type CPrinter struct {
	// contains filtered or unexported fields
}

CPrinter holds the configuration for printing. Safe for concurrent use — callbacks from socket.io event streams call the printer from goroutines other than the main one, so the messages buffer needs a mutex.

func NewCPrinter added in v0.12.6

func NewCPrinter(verbose bool) *CPrinter

NewCPrinter creates a new CPrinter instance

func (*CPrinter) Emit added in v0.27.0

func (p *CPrinter) Emit(result map[string]any) error

Emit renders the final output of a command.

  • In human mode it is a no-op — individual messages have already been streamed to stdout as they happened.
  • In json mode it merges the caller's result fields with a "messages" array of everything recorded during the run and writes a single JSON object to stdout on its own line.

The caller owns the result keys. A "messages" key in result is overwritten by the printer's recorded messages — the CLI owns that slot.

func (*CPrinter) Error added in v0.12.6

func (p *CPrinter) Error(cmd *cobra.Command, err error)

CPrinter methods — in human mode each streams the message to stdout; in JSON mode each records the message into the buffer for Emit to include in the final payload. Messages are not recorded in human mode so long-running commands don't accumulate them in memory.

func (*CPrinter) GreenPrint added in v0.12.6

func (p *CPrinter) GreenPrint(message string)

func (*CPrinter) Info added in v0.12.6

func (p *CPrinter) Info(message string)

func (*CPrinter) IsJSON added in v0.27.0

func (p *CPrinter) IsJSON() bool

IsJSON reports whether the printer is in structured JSON mode.

func (*CPrinter) Messages added in v0.27.0

func (p *CPrinter) Messages() []Message

Messages returns a copy of the messages recorded so far. Exposed mostly for tests; returning a copy keeps callers from mutating printer state.

func (*CPrinter) OrganizationInfo added in v0.12.6

func (p *CPrinter) OrganizationInfo(orgID string)

func (*CPrinter) Print added in v0.12.6

func (p *CPrinter) Print(message string)

func (*CPrinter) PrintDetail added in v0.12.6

func (p *CPrinter) PrintDetail(label, value string)

func (*CPrinter) PrintHeader added in v0.12.6

func (p *CPrinter) PrintHeader(message string)

func (*CPrinter) PrintNorm added in v0.12.6

func (p *CPrinter) PrintNorm(message string)

func (*CPrinter) PrintVerbose added in v0.16.0

func (p *CPrinter) PrintVerbose(message string)

PrintVerbose records and prints only when verbose mode is enabled.

func (*CPrinter) Prompt added in v0.12.6

func (p *CPrinter) Prompt(message string)

func (*CPrinter) SetFormat added in v0.27.0

func (p *CPrinter) SetFormat(format string)

SetFormat selects how this printer renders output. The zero value (empty string) is the default human-readable mode. FormatJSON suppresses streaming progress and buffers messages into the JSON payload emitted by Emit.

func (*CPrinter) Success added in v0.12.6

func (p *CPrinter) Success(message string)

func (*CPrinter) Warning added in v0.12.6

func (p *CPrinter) Warning(message string)

func (*CPrinter) YellowPrint added in v0.12.6

func (p *CPrinter) YellowPrint(message string)

type Message added in v0.27.0

type Message struct {
	Level string `json:"level"`
	Text  string `json:"text"`
}

Message is a user-facing line buffered by the printer in JSON output mode and emitted as part of the final JSON object produced by Emit. In human mode messages are streamed to stdout as they happen and are not buffered, so long-running commands (e.g. hx deploy monitoring a pipeline) don't accumulate them in memory.

Jump to

Keyboard shortcuts

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