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
- func ActionInputArgs(in io.Reader, usage string, usageError func(error) error) cobra.PositionalArgs
- func ActionOrTargetsArgs(in io.Reader, usage string, usageError func(error) error) cobra.PositionalArgs
- func Bind(cmd *cobra.Command, spec InputSpec)
- func Clear(command *cobra.Command)
- func ConsumeActionRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation, onError string, ...) error
- func ConsumeNDJSONRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation string, ...) error
- func FatalRecordPipeline(err error) error
- func FirstNonWhitespace(body []byte) (byte, bool)
- func IsTTY(reader io.Reader) bool
- func MarkSkipAutomaticUpdate(command *cobra.Command)
- func NewRecordActionError(code string, err error) error
- func ReadValue(reader io.Reader) (string, error)
- func Reader(command *cobra.Command, fallback io.Reader) io.Reader
- func RecordFailureStrategy(value string) (bool, error)
- func RequiredRecordID(value record.Record) (int64, error)
- func ResolvedArgs(command *cobra.Command, fallback []string) []string
- func SkipAutomaticUpdate(command *cobra.Command) bool
- func StripOneTrailingLineEnding(body []byte) []byte
- type Codec
- type InputSpec
- type Mode
- type PipelineDiagnosticError
Constants ¶
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 ¶
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 ¶
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 ¶
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 FirstNonWhitespace ¶
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 ¶
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 ¶
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 ReadValue ¶
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 ¶
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 ResolvedArgs ¶
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 ¶
SkipAutomaticUpdate reports whether this command was classified as an offline operation.
func StripOneTrailingLineEnding ¶
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" )
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 PipelineDiagnosticError ¶
type PipelineDiagnosticError struct{}
PipelineDiagnosticError 表示错误已经按管道契约写入 stderr。它让根命令保留 非零退出状态,同时不再附加普通的 "error:" 文本破坏逐行诊断。
func (*PipelineDiagnosticError) Error ¶
func (*PipelineDiagnosticError) Error() string