Documentation
¶
Index ¶
- Constants
- Variables
- func ExitCodeForCode(code string) int
- func ExitCodeForError(err error) int
- func MapAPIError(err error) error
- func RequireDaemon(client EdgeletAPIClient) error
- func WithSpinner(ctx *CLIContext, msg string, fn func() error) error
- func WithSpinnerHumanSuccess(ctx *CLIContext, msg string, fn func() (string, error)) error
- func WriteHuman(ctx *CLIContext, text string) error
- func WriteHumanConfigResult(ctx *CLIContext, human string, hasRejections bool) error
- func WriteHumanMutationResult(ctx *CLIContext, human string) error
- func WriteHumanSuccess(ctx *CLIContext, message string) error
- func WriteRouteData(ctx *CLIContext, routePath string, data map[string]any) error
- func WriteValue(ctx *CLIContext, value any) error
- type CLIContext
- type CLIError
- type ClientFactory
- type EdgeletAPIClient
- type ExecExitError
- type ExitCoder
Constants ¶
const ( CodeInvalidArgument = "INVALID_ARGUMENT" CodeForbidden = "FORBIDDEN" CodeNotFound = "NOT_FOUND" CodeConflict = "CONFLICT" CodeNotImplemented = "NOT_IMPLEMENTED" CodeInternal = "INTERNAL" )
Error codes aligned with EdgeletAPI v1 and CLI exit mapping.
const ( ExitSuccess = 0 ExitInternal = 1 ExitInvalidArgument = 2 ExitNotFound = 4 ExitConflict = 5 ExitNotImplemented = 6 )
Variables ¶
var ErrHumanOutputWritten = errors.New("cli: human output already written")
ErrHumanOutputWritten marks failures whose human-mode message was already printed to stderr.
Functions ¶
func ExitCodeForCode ¶
ExitCodeForCode maps API/CLI error codes to process exit codes.
func ExitCodeForError ¶
ExitCodeForError resolves an exit code from any error, honoring ExitCoder.
func MapAPIError ¶
MapAPIError converts EdgeletAPI errors to CLIError values.
func RequireDaemon ¶
func RequireDaemon(client EdgeletAPIClient) error
RequireDaemon returns DAEMON_UNAVAILABLE when the daemon is unreachable.
func WithSpinner ¶
func WithSpinner(ctx *CLIContext, msg string, fn func() error) error
WithSpinner runs fn with a stderr spinner in human mode. Structured output skips the spinner; the spinner is always stopped before return.
func WithSpinnerHumanSuccess ¶
func WithSpinnerHumanSuccess(ctx *CLIContext, msg string, fn func() (string, error)) error
WithSpinnerHumanSuccess runs fn with a stderr spinner in human mode and writes the returned message via WriteHumanSuccess. Structured output skips the spinner and does not write success text; callers handle structured stdout separately.
func WriteHuman ¶
func WriteHuman(ctx *CLIContext, text string) error
WriteHuman writes a preformatted human string to stdout.
func WriteHumanConfigResult ¶
func WriteHumanConfigResult(ctx *CLIContext, human string, hasRejections bool) error
WriteHumanConfigResult writes human config mutation output to stderr. The summary line gets a colored marker; accepted/rejected detail stays plain. Returns exit code 2 when hasRejections is true.
func WriteHumanMutationResult ¶
func WriteHumanMutationResult(ctx *CLIContext, human string) error
WriteHumanMutationResult writes hybrid mutation output for human mode. The first line is a success summary on stderr; any remaining lines go to stdout.
func WriteHumanSuccess ¶
func WriteHumanSuccess(ctx *CLIContext, message string) error
WriteHumanSuccess writes a human success message to stderr.
func WriteRouteData ¶
func WriteRouteData(ctx *CLIContext, routePath string, data map[string]any) error
WriteRouteData writes API payload to stdout using the selected output format.
func WriteValue ¶
func WriteValue(ctx *CLIContext, value any) error
WriteValue writes an arbitrary payload to stdout.
Types ¶
type CLIContext ¶
type CLIContext struct {
UI *ui.UI
Out io.Writer
ErrOut io.Writer
Format output.Format
Quiet bool
Verbose bool
Debug bool
Socket string
Timeout string
NoColor bool
Client EdgeletAPIClient
Version string
BuildTime string
GitCommit string
}
CLIContext carries shared runtime state for Cobra commands.
func NewCLIContext ¶
func NewCLIContext(opts ui.Options, format output.Format) *CLIContext
NewCLIContext builds a CLIContext with UI defaults.
func NewCLIContextWithWriters ¶
func NewCLIContextWithWriters(out, errOut io.Writer, opts ui.Options, format output.Format) *CLIContext
NewCLIContextWithWriters builds a CLIContext for tests.
type CLIError ¶
CLIError is a typed CLI failure with code and exit mapping.
func NewCLIError ¶
NewCLIError builds a CLIError with normalized code.
func NewDisplayedCLIError ¶
NewDisplayedCLIError builds a CLIError whose message was already written to stderr.
type ClientFactory ¶
type ClientFactory func() EdgeletAPIClient
ClientFactory creates a EdgeletAPI client.
type EdgeletAPIClient ¶
type EdgeletAPIClient interface {
Request(method, path string, requestBody any) (map[string]any, error)
RequestMultipartFile(method, path, fileField, filePath string, fields map[string]string) (map[string]any, error)
IsDaemonRunning() bool
}
EdgeletAPIClient is the EdgeletAPI v1 client surface used by CLI commands.
func DefaultClientFactory ¶
func DefaultClientFactory() EdgeletAPIClient
DefaultClientFactory returns the production EdgeletAPI client.
type ExecExitError ¶
type ExecExitError struct {
Code int
}
ExecExitError reports a remote command exit status for ms exec.
func NewExecExitError ¶
func NewExecExitError(code int) *ExecExitError
NewExecExitError builds an exec exit error.
func (*ExecExitError) Error ¶
func (e *ExecExitError) Error() string
func (*ExecExitError) ExitCode ¶
func (e *ExecExitError) ExitCode() int