Documentation
¶
Overview ¶
Package output formats documents and gates colour on stdout being a terminal, as the TypeScript CLI did: its output is routinely parsed by GitOps pipelines.
Index ¶
- Variables
- func ApplyJQ(w io.Writer, jsonText string, expression string) error
- func Bold(s string) string
- func ColorsEnabled() bool
- func Green(s string) string
- func IsJSON(content []byte) bool
- func Live() bool
- func ParseList(content []byte) ([]any, error)
- func ParseValue(content []byte) (any, error)
- func PathSegment(id string) string
- func Red(s string) string
- func WithFieldFirst(content []byte, doc *Document, field, value string) ([]byte, bool)
- type Datatype
- type Document
- func (d *Document) Delete(key string)
- func (d *Document) Get(key string) (string, bool)
- func (d *Document) MarshalJSON() ([]byte, error)
- func (d *Document) Render(datatype Datatype) ([]byte, error)
- func (d *Document) RenderFile(datatype Datatype) []byte
- func (d *Document) SetFirst(key, value string)
- func (d *Document) Value() *jsyaml.Map
Constants ¶
This section is empty.
Variables ¶
var JQ string
JQ is the --jq expression, applied to whatever JSON a command prints. Set once from the root command's flags.
Functions ¶
func ApplyJQ ¶
ApplyJQ filters JSON through the --jq expression and writes each result on its own line: strings raw, everything else as indented JSON, as `gh --jq` does. jq itself is not needed, the expression runs in-process.
func ColorsEnabled ¶
func ColorsEnabled() bool
ColorsEnabled reports whether output is coloured: only on a terminal, unless NO_COLOR or FORCE_COLOR say otherwise.
func IsJSON ¶
IsJSON reports whether content is a JSON document, as JSON.parse would accept it. A leading byte order mark, which Windows editors write, is ignored.
func Live ¶
func Live() bool
Live reports whether output can be redrawn in place, as `execution watch` does.
func ParseList ¶
ParseList reads a JSON array, or JSON values one after another as newline-delimited JSON sends them. The platform streams the audit log that way, although its spec says array, so both are read.
func ParseValue ¶
ParseValue reads any JSON or YAML value, such as a placeholders file that is a list.
func PathSegment ¶
PathSegment reduces an id from the platform to one path segment, so that one containing "../" cannot write outside the chosen directory; Base alone leaves "..".
func WithFieldFirst ¶
WithFieldFirst returns YAML content with `field: value` added as its first key, and the rest of the file, comments and anchors included, kept byte for byte. It reports false when a line in front would not do that, as for a flow mapping `{...}` or a file that already holds the field, empty; the caller then renders the document instead.
Types ¶
type Datatype ¶
type Datatype string
func ResolveDatatype ¶
ResolveDatatype: an explicit type first, then the file's extension, then YAML.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a JSON or YAML object as the TypeScript CLI held it: a JavaScript value with JavaScript's key order and number semantics. Files written from it are kept in Git, so they have to come out exactly as they did before.
func NewDocument ¶
func ParseDocument ¶
ParseDocument reads JSON or YAML; JSON is valid YAML, so one parser handles both. Anchors, aliases and merge keys (`<<:`) are resolved, as js-yaml's load did.
func (*Document) MarshalJSON ¶
MarshalJSON sends a document as a request body, as JSON.stringify did.
func (*Document) Render ¶
Render as `get` printed it: JSON.stringify(value, undefined, 2), or js-yaml's dump.
func (*Document) RenderFile ¶
RenderFile as the TypeScript CLI wrote files: compact JSON without a newline, or YAML.