jsonout

package
v0.3.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonout implements the --json mode shared by the porthole and portholed command lines. In this mode stdout carries only JSON: one object (or array) for a command that ends by itself, one compact object per line (JSON Lines) for a command that keeps running and reports events. Everything meant for people goes to stderr or is left out.

Index

Constants

View Source
const Flag = "json"

Flag is the name of the persistent flag of the root commands.

Variables

This section is empty.

Functions

func AddFlag

func AddFlag(root *cobra.Command)

AddFlag registers the persistent --json flag on root.

func Enabled

func Enabled(cmd *cobra.Command) bool

Enabled reports whether --json was given to cmd or to one of its parents.

func InArgs

func InArgs(args []string) bool

InArgs reports whether args ask for --json. It is for command lines that failed to parse, where the flag set holds no value yet.

func Write

func Write(w io.Writer, v any) error

Write writes v as one indented JSON document.

func WriteError

func WriteError(w io.Writer, code, message string) error

WriteError writes the failure document as one line.

Types

type ErrorBody

type ErrorBody struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorBody is the content of the "error" member of a failure document.

type ErrorDoc

type ErrorDoc struct {
	Error ErrorBody `json:"error"`
}

ErrorDoc is what a failed command writes to stdout in --json mode: {"error":{"code":"...","message":"..."}}.

type Lines

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

Lines writes JSON Lines: one compact object per call, safe for concurrent use.

func NewLines

func NewLines(w io.Writer) *Lines

NewLines returns a Lines that writes to w.

func (*Lines) Emit

func (l *Lines) Emit(v any) error

Emit writes v as one line.

Jump to

Keyboard shortcuts

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