output

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitUsage     = 1
	ExitNotFound  = 2
	ExitAuth      = 3
	ExitForbidden = 4
	ExitRateLimit = 5
	ExitNetwork   = 6
	ExitAPI       = 7
	ExitAmbiguous = 8
)

Variables

This section is empty.

Functions

func ErrJQConflict added in v0.1.1

func ErrJQConflict(flag string) *apierr.Error

ErrJQConflict reports an output flag that cannot be combined with --jq.

func ErrJQNotSupported added in v0.1.1

func ErrJQNotSupported(command string) *apierr.Error

ErrJQNotSupported reports a command that produces a dedicated raw format.

func ErrJQRuntime added in v0.1.1

func ErrJQRuntime(cause error) *apierr.Error

ErrJQRuntime reports a failure while evaluating a built-in jq expression.

func ErrJQValidation added in v0.1.1

func ErrJQValidation(cause error) *apierr.Error

ErrJQValidation reports an invalid built-in jq expression.

func ExitCodeFor

func ExitCodeFor(err error) int

func MarshalIndentJSON added in v0.2.0

func MarshalIndentJSON(v any) ([]byte, error)

MarshalIndentJSON is json.MarshalIndent with the C1 controls escaped, indented the way every envelope is.

func MarshalJSON added in v0.2.0

func MarshalJSON(v any) ([]byte, error)

MarshalJSON is json.Marshal with the C1 controls escaped.

func NormalizeJSONNumbers

func NormalizeJSONNumbers(data []byte) (any, error)

func TruncationNotice

func TruncationNotice(shown, total int) string

func ValidateJQFilter added in v0.1.1

func ValidateJQFilter(filter string) error

ValidateJQFilter confirms that a built-in jq expression is ready to run.

Types

type Breadcrumb struct {
	Action      string `json:"action"`
	Command     string `json:"command"`
	Description string `json:"description"`
}

type ErrorResponse

type ErrorResponse struct {
	OK    bool           `json:"ok"`
	Error string         `json:"error"`
	Code  string         `json:"code"`
	Hint  string         `json:"hint,omitempty"`
	Meta  map[string]any `json:"meta,omitempty"`
}

type Format

type Format int
const (
	FormatAuto Format = iota
	FormatJSON
	FormatStyled
	FormatQuiet
	FormatIDs
	FormatCount
	FormatMarkdown
	// FormatHTML is the raw writer behind --html: the original HTML of the one thing a
	// command reads, written to a pipe or a file. A thread is written as an HTML document
	// with an <article> per entry, since it has entries to frame; a single body — a
	// journal entry, a contact's note — is written as a fragment, as HEY served it, since
	// one body is what gets pasted elsewhere. It carries no envelope, so OK refuses it
	// and --stats has nowhere to go; the commands that support it write the HTML
	// themselves.
	FormatHTML
)

func FormatFromFlags

func FormatFromFlags(jsonFlag, quiet, idsOnly, count, markdown, styled, agent bool) Format

type Options

type Options struct {
	Format   Format
	Stdout   io.Writer
	Stderr   io.Writer
	JQFilter string
}

type Response

type Response struct {
	OK          bool           `json:"ok"`
	Data        any            `json:"data,omitempty"`
	Summary     string         `json:"summary,omitempty"`
	Notice      string         `json:"notice,omitempty"`
	Breadcrumbs []Breadcrumb   `json:"breadcrumbs,omitempty"`
	Meta        map[string]any `json:"meta,omitempty"`
}

type ResponseOption

type ResponseOption func(*Response)

func WithBreadcrumbs

func WithBreadcrumbs(b ...Breadcrumb) ResponseOption

func WithMeta

func WithMeta(key string, value any) ResponseOption

func WithNotice

func WithNotice(s string) ResponseOption

func WithSummary

func WithSummary(s string) ResponseOption

type Writer

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

func New

func New(opts Options) *Writer

func (*Writer) EffectiveFormat

func (w *Writer) EffectiveFormat() Format

func (*Writer) Err

func (w *Writer) Err(err error)

func (*Writer) IsStyled

func (w *Writer) IsStyled() bool

func (*Writer) OK

func (w *Writer) OK(data any, opts ...ResponseOption) error

func (*Writer) RequestedFormat added in v0.2.0

func (w *Writer) RequestedFormat() Format

RequestedFormat reports the format the caller asked for by flag, FormatAuto when they asked for nothing and the writer is left to read the terminal.

Jump to

Keyboard shortcuts

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