output

package
v1.1.2-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	CodeUsage          = "usage_error"
	CodeAuthentication = "authentication_required"
	CodePermission     = "permission_denied"
	CodeNotFound       = "not_found"
	CodeConflict       = "conflict"
	CodeNetwork        = "network_error"
	CodeTimeout        = "timeout"
	CodeServer         = "server_error"
	CodeExecution      = "execution_failed"
	CodeFileTransfer   = "file_transfer_failed"
)

Variables

This section is empty.

Functions

func AddGlobalFlags

func AddGlobalFlags(command *cobra.Command)

AddGlobalFlags 为根命令登记统一输出参数。 AddGlobalFlags registers shared output flags on the root command.

func ParsePick

func ParsePick(value string) []string

ParsePick 解析并去重顶层字段名称。 ParsePick parses and deduplicates top-level field names.

Types

type CLIError

type CLIError struct {
	Code      string
	Message   string
	Retryable bool
	RequestID string
	ExitCode  ExitCode
	Cause     error
}

CLIError 保存可稳定输出和映射退出码的错误信息。 CLIError stores error information that can be rendered and mapped to a stable exit code.

func ClassifyError

func ClassifyError(err error) *CLIError

ClassifyError 将未知错误转换为稳定的 CLI 错误分类。 ClassifyError converts an unknown error into a stable CLI error classification.

func NewError

func NewError(code, message string, exitCode ExitCode, retryable bool) *CLIError

NewError 创建带有稳定分类的 CLI 错误。 NewError creates a CLI error with a stable classification.

func WrapError

func WrapError(err error, code, message string, exitCode ExitCode, retryable bool) *CLIError

WrapError 创建保留原始原因的 CLI 错误。 WrapError creates a CLI error that retains its original cause.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

type Event

type Event struct {
	Event          string   `json:"event"`
	Code           string   `json:"code,omitempty"`
	Message        string   `json:"message,omitempty"`
	Retryable      *bool    `json:"retryable,omitempty"`
	RequestID      string   `json:"request_id,omitempty"`
	OperationID    string   `json:"operation_id,omitempty"`
	ExecutionID    string   `json:"execution_id,omitempty"`
	ConfirmationID string   `json:"confirmation_id,omitempty"`
	RiskLevel      string   `json:"risk_level,omitempty"`
	ExpiresAt      string   `json:"expires_at,omitempty"`
	Level          string   `json:"level,omitempty"`
	Progress       *int     `json:"progress,omitempty"`
	MissingFields  []string `json:"missing_fields,omitempty"`
	// JobID 关联 sync 作业实例,供 --wait 进度/日志事件使用。
	// JobID links a sync job instance for --wait progress/log events.
	JobID uint `json:"job_id,omitempty"`
	// Status 为作业或执行状态快照。
	// Status is a job or execution status snapshot.
	Status string `json:"status,omitempty"`
	// SyncState 反映 STX 与引擎对账观察面(读库字段)。
	// SyncState reflects STX engine reconciler observability (DB read path).
	SyncState string `json:"sync_state,omitempty"`
	// SyncLagMs 为 API 派生的同步滞后毫秒数(可选)。
	// SyncLagMs is optional derived sync lag in milliseconds from the API.
	SyncLagMs *int64 `json:"sync_lag_ms,omitempty"`
	// NextOffset 为日志增量读偏移令牌。
	// NextOffset is the incremental log read offset token.
	NextOffset string `json:"next_offset,omitempty"`
	// Logs 为 log_chunk 事件的增量正文(含真实换行,JSON 中转义)。
	// Logs carries incremental text for log_chunk events (real newlines, JSON-escaped).
	Logs string `json:"logs,omitempty"`
	// Lines 为按行拆分的日志,便于传输后仍可按行阅读。
	// Lines is the line-split form so transferred logs stay readable per line.
	Lines []string `json:"lines,omitempty"`
	// EmptyReason 说明日志暂不可用(如 logs_not_ready)。
	// EmptyReason explains missing logs (e.g. logs_not_ready).
	EmptyReason string `json:"empty_reason,omitempty"`
}

Event 表示写入 stderr 的单行 JSON 事件。 Event represents one JSON event written to stderr.

type EventFormat added in v1.2.0

type EventFormat string

EventFormat controls how EventWriter serializes events to the sink. EventFormat 控制 EventWriter 如何把事件写到输出。

const (
	// EventFormatJSON writes one NDJSON object per event (machine-oriented).
	// EventFormatJSON 每个事件写一行 NDJSON(机器可读)。
	EventFormatJSON EventFormat = "json"
	// EventFormatText writes plain human-readable lines (DolphinScheduler / terminal friendly).
	// EventFormatText 写纯文本行(适合 DS / 终端阅读)。
	EventFormatText EventFormat = "text"
)

type EventWriter

type EventWriter struct {
	// contains filtered or unexported fields
}

EventWriter 以并发安全方式写入事件(NDJSON 或纯文本)。 EventWriter writes events safely as NDJSON or plain text.

func NewEventWriter

func NewEventWriter(writer io.Writer) *EventWriter

NewEventWriter 创建默认 NDJSON 事件写入器。 NewEventWriter creates a stderr event writer in NDJSON mode.

func NewTextEventWriter added in v1.2.0

func NewTextEventWriter(writer io.Writer) *EventWriter

NewTextEventWriter 创建纯文本事件写入器(人类可读,供 --wait 默认使用)。 NewTextEventWriter creates a plain-text event writer (human-readable; default for --wait).

func (*EventWriter) Emit

func (w *EventWriter) Emit(event Event) error

Emit 按当前格式写入一个事件。 Emit writes one event using the configured format.

func (*EventWriter) EmitError

func (w *EventWriter) EmitError(err error) error

EmitError 写入最终错误事件。 EmitError writes the final error event.

func (*EventWriter) SetFormat added in v1.2.0

func (w *EventWriter) SetFormat(format EventFormat)

SetFormat switches serialization format; empty keeps current. SetFormat 切换序列化格式;空值保持不变。

type ExitCode

type ExitCode int

ExitCode 是 STX CLI 的稳定进程退出码。 ExitCode is a stable STX CLI process exit code.

const (
	ExitSuccess        ExitCode = 0
	ExitUsage          ExitCode = 2
	ExitAuthentication ExitCode = 3
	ExitPermission     ExitCode = 4
	ExitNotFound       ExitCode = 5
	ExitConflict       ExitCode = 6
	ExitNetwork        ExitCode = 7
	ExitTimeout        ExitCode = 8
	ExitServer         ExitCode = 9
	ExitExecution      ExitCode = 10
	ExitFileTransfer   ExitCode = 11
)

type Format

type Format string

Format 表示 CLI 最终输出格式。 Format represents the final CLI output format.

const (
	FormatJSON  Format = "json"
	FormatTable Format = "table"
	FormatYAML  Format = "yaml"
	FormatRaw   Format = "raw"
)

func ParseFormat

func ParseFormat(value string) (Format, error)

ParseFormat 校验输出格式。 ParseFormat validates an output format.

type Options

type Options struct {
	Format Format
	Pick   []string
}

Options 控制本次结果的格式和字段选择。 Options controls formatting and field selection for one result.

func OptionsFromCommand

func OptionsFromCommand(command *cobra.Command) (Options, error)

OptionsFromCommand 从 Cobra 命令解析统一输出参数。 OptionsFromCommand parses shared output options from a Cobra command.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer 将安全业务结果写入 stdout,并将处理事件写入 stderr。 Renderer writes safe business results to stdout and processing events to stderr.

func NewRenderer

func NewRenderer(stdout io.Writer, events *EventWriter) *Renderer

NewRenderer 创建结果渲染器。 NewRenderer creates a result renderer.

func (*Renderer) Render

func (r *Renderer) Render(result Result, options Options) error

Render 应用字段选择后输出结果。 Render applies field selection and writes the result.

type Result

type Result struct {
	APIVersion  string     `json:"api_version" yaml:"api_version"`
	OperationID string     `json:"operation_id" yaml:"operation_id"`
	RequestID   string     `json:"request_id" yaml:"request_id"`
	Data        any        `json:"data" yaml:"data"`
	Impact      any        `json:"impact,omitempty" yaml:"impact,omitempty"`
	ResultMeta  ResultMeta `json:"result_meta" yaml:"result_meta"`
}

Result 是普通 CLI 命令的稳定输出结构。 Result is the stable output envelope for regular CLI commands.

func NewResult

func NewResult(operationID, requestID string, data any) Result

NewResult 创建完整的普通命令结果。 NewResult creates a complete regular command result.

type ResultMeta

type ResultMeta struct {
	Complete    bool   `json:"complete" yaml:"complete"`
	Reason      string `json:"reason,omitempty" yaml:"reason,omitempty"`
	NextCommand string `json:"next_command,omitempty" yaml:"next_command,omitempty"`
}

ResultMeta 只保存跨命令通用的完整性信息。 ResultMeta stores only completeness information shared across commands.

Jump to

Keyboard shortcuts

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