batch

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 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 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 skips stdin entirely

Precedence: --from-file wins, then positional args, then stdin. Callers wiring an interactive TTY must pass nil to opt out — otherwise a blocking Read on the terminal will hang the command and swallow Ctrl+C. 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