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 ¶
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 ¶
AddGlobalFlags 为根命令登记统一输出参数。 AddGlobalFlags registers shared output flags on the root command.
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 ¶
ClassifyError 将未知错误转换为稳定的 CLI 错误分类。 ClassifyError converts an unknown error into a stable CLI error classification.
func NewError ¶
NewError 创建带有稳定分类的 CLI 错误。 NewError creates a CLI error with a stable classification.
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.
func ParseFormat ¶
ParseFormat 校验输出格式。 ParseFormat validates an output format.
type Options ¶
Options 控制本次结果的格式和字段选择。 Options controls formatting and field selection for one result.
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.
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.
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.