output

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 25, 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"`
}

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

type EventWriter

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

EventWriter 以并发安全方式写入 NDJSON 事件。 EventWriter writes NDJSON events safely across concurrent callers.

func NewEventWriter

func NewEventWriter(writer io.Writer) *EventWriter

NewEventWriter 创建 stderr 事件写入器。 NewEventWriter creates a stderr event writer.

func (*EventWriter) Emit

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

Emit 写入一个完整 JSON 对象并追加换行。 Emit writes one complete JSON object followed by a newline.

func (*EventWriter) EmitError

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

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

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