Documentation
¶
Index ¶
- Constants
- Variables
- func IsTerminal() bool
- func PriorityStyle(name string) lipgloss.Style
- func RenderActionJSON(w io.Writer, env ActionEnvelope) error
- func RenderCSV(w io.Writer, headers []string, rows [][]string) error
- func RenderErrorJSON(w io.Writer, env ErrorEnvelope) error
- func RenderJSON(w io.Writer, v interface{}) error
- func RenderTable(w io.Writer, headers []string, rows [][]string, noColor bool)
- func StartSpinner(msg string, isTTY bool) func()
- func StatusStyle(name string) lipgloss.Style
- func SupportsWarnings(format string) bool
- type ActionEnvelope
- type ErrorDetail
- type ErrorEnvelope
- type KeyValue
- type Printer
- type StdPrinter
- func (p *StdPrinter) Action(action, resource string, id any, humanMsg string)
- func (p *StdPrinter) CSV(headers []string, rows [][]string)
- func (p *StdPrinter) Detail(pairs []KeyValue)
- func (p *StdPrinter) Error(msg string)
- func (p *StdPrinter) Format() string
- func (p *StdPrinter) JSON(v interface{})
- func (p *StdPrinter) Outcome(ok bool, action, resource string, id any, humanMsg string)
- func (p *StdPrinter) Resource(v any, humanMsg string)
- func (p *StdPrinter) Spinner(msg string) func()
- func (p *StdPrinter) Success(msg string)
- func (p *StdPrinter) Table(headers []string, rows [][]string)
- func (p *StdPrinter) Warning(msg string)
Constants ¶
const ( ErrCodeNotFound = "not_found" ErrCodeAuthFailed = "auth_failed" ErrCodeForbidden = "forbidden" ErrCodeValidationFailed = "validation_failed" ErrCodeServerError = "server_error" ErrCodeUnknown = "unknown" )
Error codes emitted in JSON error envelopes.
const ( ActionCreated = "created" ActionUpdated = "updated" ActionDeleted = "deleted" ActionClosed = "closed" ActionReopened = "reopened" ActionAssigned = "assigned" ActionCommented = "commented" ActionLogged = "logged" ActionUserAdded = "user_added" ActionUserRemoved = "user_removed" ActionLoggedIn = "logged_in" ActionLoggedOut = "logged_out" ActionSwitched = "switched" ActionInstalled = "installed" ActionOpened = "opened" )
Action actions exposed by no-body mutators. Keep the vocabulary small.
const ( FormatTable = "table" FormatJSON = "json" FormatCSV = "csv" )
Format constants for output modes.
Variables ¶
var ( StyleNew = lipgloss.NewStyle().Foreground(lipgloss.Color("10")) StyleInProgress = lipgloss.NewStyle().Foreground(lipgloss.Color("11")) StyleResolved = lipgloss.NewStyle().Foreground(lipgloss.Color("12")) StyleClosed = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) StyleRejected = lipgloss.NewStyle().Foreground(lipgloss.Color("9")) StyleHighPrio = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true) StyleNormalPrio = lipgloss.NewStyle().Foreground(lipgloss.Color("7")) StyleLowPrio = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) StyleID = lipgloss.NewStyle().Foreground(lipgloss.Color("6")).Bold(true) StyleHeader = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("15")) StyleLabel = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) StyleSuccess = lipgloss.NewStyle().Foreground(lipgloss.Color("10")) StyleError = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true) StyleWarning = lipgloss.NewStyle().Foreground(lipgloss.Color("11")) )
Functions ¶
func PriorityStyle ¶
PriorityStyle returns the appropriate style for a priority name.
func RenderActionJSON ¶
func RenderActionJSON(w io.Writer, env ActionEnvelope) error
RenderActionJSON writes an action envelope as pretty-printed JSON.
func RenderErrorJSON ¶
func RenderErrorJSON(w io.Writer, env ErrorEnvelope) error
RenderErrorJSON writes an error envelope as pretty-printed JSON.
func RenderJSON ¶
RenderJSON renders a value as pretty-printed JSON to the writer.
func RenderTable ¶
RenderTable renders a table with headers and rows to the writer.
func StartSpinner ¶
StartSpinner starts a spinner with the given message and returns a stop function.
func StatusStyle ¶
StatusStyle returns the appropriate style for a status name.
func SupportsWarnings ¶
SupportsWarnings reports whether human-readable warnings should be emitted for the selected output format.
Types ¶
type ActionEnvelope ¶
type ActionEnvelope struct {
Ok bool `json:"ok"`
Action string `json:"action"`
Resource string `json:"resource"`
ID any `json:"id,omitempty"`
Message string `json:"message,omitempty"`
}
ActionEnvelope is the JSON shape emitted by no-body mutators.
type ErrorDetail ¶
type ErrorDetail struct {
Message string `json:"message"`
Code string `json:"code,omitempty"`
Details []string `json:"details,omitempty"`
}
ErrorDetail describes a failed command execution.
type ErrorEnvelope ¶
type ErrorEnvelope struct {
Error ErrorDetail `json:"error"`
}
ErrorEnvelope is the JSON shape emitted for command failures in JSON mode.
type Printer ¶
type Printer interface {
Table(headers []string, rows [][]string)
Detail(pairs []KeyValue)
JSON(v interface{})
CSV(headers []string, rows [][]string)
Success(msg string)
Error(msg string)
Warning(msg string)
// Outcome emits a completed command result. In JSON mode this writes a
// stable envelope to stdout. In other modes it writes the human message to
// stderr as either success or warning text.
Outcome(ok bool, action, resource string, id any, humanMsg string)
// Resource emits a resource body in JSON mode and a human success message
// in other formats.
Resource(v any, humanMsg string)
// Action emits a completed-mutation result. In JSON mode this writes a
// compact action envelope to stdout. In any other mode it writes the
// human message to stderr via Success.
Action(action, resource string, id any, humanMsg string)
Spinner(msg string) func()
Format() string
}
Printer handles all output rendering.
type StdPrinter ¶
type StdPrinter struct {
// contains filtered or unexported fields
}
StdPrinter is the standard implementation of Printer.
func NewStdPrinter ¶
func NewStdPrinter(out, errOut io.Writer, isTTY, noColor bool, format string) *StdPrinter
NewStdPrinter creates a new StdPrinter.
func (*StdPrinter) Action ¶
func (p *StdPrinter) Action(action, resource string, id any, humanMsg string)
func (*StdPrinter) CSV ¶
func (p *StdPrinter) CSV(headers []string, rows [][]string)
func (*StdPrinter) Detail ¶
func (p *StdPrinter) Detail(pairs []KeyValue)
func (*StdPrinter) Error ¶
func (p *StdPrinter) Error(msg string)
func (*StdPrinter) Format ¶
func (p *StdPrinter) Format() string
func (*StdPrinter) JSON ¶
func (p *StdPrinter) JSON(v interface{})
func (*StdPrinter) Outcome ¶
func (p *StdPrinter) Outcome(ok bool, action, resource string, id any, humanMsg string)
func (*StdPrinter) Resource ¶
func (p *StdPrinter) Resource(v any, humanMsg string)
func (*StdPrinter) Spinner ¶
func (p *StdPrinter) Spinner(msg string) func()
func (*StdPrinter) Success ¶
func (p *StdPrinter) Success(msg string)
func (*StdPrinter) Table ¶
func (p *StdPrinter) Table(headers []string, rows [][]string)
func (*StdPrinter) Warning ¶
func (p *StdPrinter) Warning(msg string)