batch

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package batch collects multi-input arguments (positional args, stdin, or --from-file) and renders per-input results as a stable JSON envelope.

The envelope shape is the contract: agents that piped 50 PURLs into the CLI can rely on receiving a 50-element array with matching .input keys and per-row .data or .error. Never break this shape.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoInputs = errors.New("no inputs provided")

ErrNoInputs is returned by CollectInputs callers when they need to surface "you provided nothing" as a validation error.

Functions

func CollectInputs

func CollectInputs(args []string, fromFile string, stdin io.Reader) ([]string, error)

CollectInputs resolves the set of inputs to operate on.

args      - positional CLI arguments (caller passes cobra's args slice)
fromFile  - value of --from-file (empty = unset)
stdin     - reader to use for stdin fallback; nil defaults to os.Stdin

Precedence: --from-file wins, then positional args, then stdin if it is not a terminal. Empty/whitespace lines and leading '#' comment lines are skipped. Returns an empty slice if no source provided any input.

Types

type Result

type Result struct {
	Input string `json:"input"`
	Data  any    `json:"data,omitempty"`
	Error string `json:"error,omitempty"`
}

Result is one row of the batch output envelope.

func ResultFromData

func ResultFromData(input string, data any) Result

ResultFromData builds a success Result.

func ResultFromError

func ResultFromError(input string, err error) Result

ResultFromError builds a failure Result. If the error is nil this is equivalent to ResultFromData with data=nil — usually you'd call ResultFromData directly in that case.

Jump to

Keyboard shortcuts

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