engine package - github.com/troll-warlord/anyq/internal/engine - Go Packages

engine

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package engine provides a unified parse → query → serialize pipeline. It accepts any supported format as input, runs a jq expression against it, and serializes the result to the requested output format.

Index

Constants

This section is empty.

Variables

View Source
var ErrExitStatus = fmt.Errorf("exit status 1")

ErrExitStatus is returned when --exit-status is set and the last value is false/null.

Functions

func Parse

func Parse(data []byte, fmt_ detector.Format) (interface{}, error)

Parse converts raw bytes in the given format to a generic Go value. It is the exported counterpart of the internal parse function, intended for use by sibling packages (diff, validator) that need parsed data without running a jq query.

func ParseMulti added in v1.1.0

func ParseMulti(data []byte, fmt_ detector.Format) ([]interface{}, error)

ParseMulti parses all documents from data and returns them as a slice. For JSON it uses a streaming decoder so concatenated objects (e.g. the output of `go list -json ./...`) are each returned as a separate element. For YAML it splits on `---` document separators. For TOML there is only ever one document, so the slice has length 1.

func Run

func Run(r io.Reader, w io.Writer, query string, data []byte, opts Options) error

Run executes the full pipeline: read → detect → parse → query → serialize → write.

func RunValues added in v1.1.0

func RunValues(w io.Writer, query string, inputs []interface{}, opts Options) error

RunValues executes query against a pre-parsed slice of values. The slice is passed directly as the jq input — used by slurp mode where all documents are combined into a single array before querying.

Types

type Options

type Options struct {
	InputFormat  detector.Format // FormatUnknown means auto-detect from content
	OutputFormat detector.Format // FormatUnknown means same as input
	Pretty       bool            // pretty-print output (JSON only; YAML/TOML are always pretty)
	RawOutput    bool            // -r: print strings without quotes
	Compact      bool            // -c: compact JSON output
	NullInput    bool            // -n: use null as input (no parsing)
	ExitStatus   bool            // -e: exit 1 if last value is false/null
	Color        bool            // enable ANSI syntax highlighting on output
}

Options controls engine behaviour.

Jump to

Keyboard shortcuts

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