cmdout

package
v0.11.0-a.11 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandName

func CommandName(cmd *cobra.Command) string

func EncodeDocument

func EncodeDocument(format Format, value any) ([]byte, error)

func EncodeRecord

func EncodeRecord(format Format, value any) ([]byte, error)

func Fail

func Fail(code Code, message string, cause error) error

func FailWithDiagnostics

func FailWithDiagnostics(
	code Code,
	message string,
	cause error,
	diagnostics []diagnostic.Diagnostic,
) error

func FormatHelp

func FormatHelp() string

func IsReported

func IsReported(err error) bool

func PrintUnreportedError

func PrintUnreportedError(cmd *cobra.Command, err error)

func Reported

func Reported(err error) error

func WithFiles

func WithFiles(err error, files []filechange.Change) error

func WriteCommandError

func WriteCommandError(
	cmd *cobra.Command,
	format Format,
	collected []diagnostic.Diagnostic,
	failure error,
) error

func WriteDocument

func WriteDocument(out io.Writer, format Format, value any) error

func WriteRecord

func WriteRecord(out io.Writer, format Format, value any) error

Types

type Code

type Code string
const (
	CodeInvalidArgs    Code = "unobin.command.invalid-args"
	CodeIO             Code = "unobin.command.io"
	CodeFailed         Code = "unobin.command.failed"
	CodeStdoutConflict Code = "unobin.command.stdout-conflict"
)

type CommandError

type CommandError struct {
	Kind          string                  `json:"kind"           ub:"kind"`
	FormatVersion int                     `json:"format-version" ub:"format-version"`
	Command       string                  `json:"command"        ub:"command"`
	Code          Code                    `json:"code"           ub:"code"`
	Message       string                  `json:"message"        ub:"message"`
	Diagnostics   []diagnostic.Diagnostic `json:"diagnostics"    ub:"diagnostics"`
	Files         []filechange.Change     `json:"files"          ub:"files"`
}

type Failure

type Failure struct {
	Code        Code
	Message     string
	Cause       error
	Diagnostics []diagnostic.Diagnostic
	Files       []filechange.Change
}

func AsFailure

func AsFailure(err error) (*Failure, bool)

func (*Failure) Error

func (e *Failure) Error() string

func (*Failure) Unwrap

func (e *Failure) Unwrap() error

type Format

type Format string
const (
	FormatText   Format = "text"
	FormatJSON   Format = "json"
	FormatUnobin Format = "unobin"
)

func ParseFormat

func ParseFormat(value string) (Format, error)

func (Format) Machine

func (f Format) Machine() bool

type ReportedError

type ReportedError struct {
	Err error
}

func (*ReportedError) Error

func (e *ReportedError) Error() string

func (*ReportedError) Unwrap

func (e *ReportedError) Unwrap() error

Jump to

Keyboard shortcuts

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