pipeline

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 15 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 pipeline owns the CLI's explicit stdin input codecs and their resolved per-command state. It does not know any Pixiv or FANBOX business semantics.

Index

Constants

View Source
const AnnotationKey = "pixiv-cli.input-spec"

AnnotationKey lets architecture checks prove that a command has a declared codec without inspecting Use strings or inferring arity from help text.

Variables

This section is empty.

Functions

func ActionInputArgs

func ActionInputArgs(in io.Reader, usage string, usageError func(error) error) cobra.PositionalArgs

ActionInputArgs 校验最多一个显式 ID;没有位置参数时仅允许真实管道输入。 usageError 由根控制器注入,以保留 CLI 的 usage exit code 语义。

func ActionOrTargetsArgs

func ActionOrTargetsArgs(in io.Reader, usage string, usageError func(error) error) cobra.PositionalArgs

ActionOrTargetsArgs 允许显式资源,也允许从 stdin 读取 NDJSON 记录。

func Bind

func Bind(cmd *cobra.Command, spec InputSpec)

Bind attaches an InputSpec to cmd. It wraps the existing positional validator and RunE so business code observes the resolved positional slice, while record consumers can retrieve the replayable reader from Reader.

func Clear

func Clear(command *cobra.Command)

Clear releases resolver state after a Cobra tree finishes one execution. Callers that execute embedded command trees should invoke it in a defer.

func ConsumeActionRecords

func ConsumeActionRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation, onError string, allowedTypes map[string]struct{}, invoke func(context.Context, int64) error, usageError func(error) error) error

ConsumeActionRecords 在一条 operation snapshot 上顺序执行记录动作;它不缓存 整个输入,因此大管道只保留当前 Record。

func ConsumeNDJSONRecords

func ConsumeNDJSONRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation string, failFast bool, consume func(context.Context, record.Record) error) error

consumeNDJSONRecords 逐行解析 NDJSON 并顺序处理记录。它不使用 Scanner,避免 合法的大记录受隐藏 token 限制;每次回调结束后才读取下一行,以便取消后不启动新任务。

func FatalRecordPipeline

func FatalRecordPipeline(err error) error

func FirstNonWhitespace

func FirstNonWhitespace(body []byte) (byte, bool)

FirstNonWhitespace returns the first byte that is not JSON whitespace. The record codec only needs the JSON-defined leading whitespace set; keeping the check byte-oriented avoids decoding or rewriting opaque input bytes.

func IsTTY

func IsTTY(reader io.Reader) bool

IsTTY recognizes only an actual terminal file. In-memory and pipe readers are intentionally treated as non-TTY so embedded callers get pipe semantics.

func MarkSkipAutomaticUpdate

func MarkSkipAutomaticUpdate(command *cobra.Command)

MarkSkipAutomaticUpdate marks a command execution as offline. It is used by the auth owner after bundle classification and is consumed by the update command owner; token imports retain the normal update behavior.

func NewRecordActionError

func NewRecordActionError(code string, err error) error

func ReadValue

func ReadValue(reader io.Reader) (string, error)

ReadValue reads the complete stream and removes exactly one trailing LF or CRLF. It does not trim whitespace, split words, or impose a size limit.

func Reader

func Reader(command *cobra.Command, fallback io.Reader) io.Reader

Reader returns the replayable reader selected by the command's input codec. TextOrRecord record mode uses it to preserve streaming NDJSON behavior.

func RecordFailureStrategy

func RecordFailureStrategy(value string) (bool, error)

func RequiredRecordID

func RequiredRecordID(value record.Record) (int64, error)

func ResolvedArgs

func ResolvedArgs(command *cobra.Command, fallback []string) []string

ResolvedArgs returns the args produced by the command's InputSpec. It is useful to command owners that call a helper outside the wrapped RunE.

func SkipAutomaticUpdate

func SkipAutomaticUpdate(command *cobra.Command) bool

SkipAutomaticUpdate reports whether this command was classified as an offline operation.

func StripOneTrailingLineEnding

func StripOneTrailingLineEnding(body []byte) []byte

StripOneTrailingLineEnding preserves all input except one final LF or CRLF.

Types

type Codec

type Codec string

Codec identifies the input protocol a command explicitly owns.

const (
	// NoInput keeps stdin reserved for command-specific protocols such as MCP.
	NoInput Codec = "none"
	// TextValue maps the complete stdin stream to one positional value.
	TextValue Codec = "text-value"
	// TextOrRecord distinguishes one raw value from the canonical NDJSON stream.
	TextOrRecord Codec = "text-or-record"
)

func CodecOf

func CodecOf(command *cobra.Command) Codec

CodecOf reports the explicit codec annotation attached by Bind.

type InputSpec

type InputSpec struct {
	Codec        Codec
	MinArgs      int
	MaxArgs      int
	FillPosition int
	Reader       io.Reader
	UsageError   func(error) error
	Enabled      func(*cobra.Command, []string) bool
	IsTTY        func(io.Reader) bool
}

InputSpec is the explicit input contract for one Cobra command.

FillPosition is the zero-based positional slot filled by stdin. A command with one required or optional value normally uses zero. A command such as "config set KEY [VALUE]" uses one, so an explicit KEY remains the first argument and only the omitted VALUE is read. MaxArgs is -1 for variadic commands.

type Mode

type Mode string

Mode is the result of resolving a TextOrRecord stream.

const (
	TextMode   Mode = "text"
	RecordMode Mode = "record"
)

func ModeOf

func ModeOf(command *cobra.Command) Mode

ModeOf reports the classification performed for the current command.

type PipelineDiagnosticError

type PipelineDiagnosticError struct{}

PipelineDiagnosticError 表示错误已经按管道契约写入 stderr。它让根命令保留 非零退出状态,同时不再附加普通的 "error:" 文本破坏逐行诊断。

func (*PipelineDiagnosticError) Error

Jump to

Keyboard shortcuts

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