run

package
v1.0.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: EPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInvalidArgument   = "INVALID_ARGUMENT"
	CodeUnauthorized      = "UNAUTHORIZED"
	CodeForbidden         = "FORBIDDEN"
	CodeNotFound          = "NOT_FOUND"
	CodeConflict          = "CONFLICT"
	CodeNotImplemented    = "NOT_IMPLEMENTED"
	CodeDaemonUnavailable = "DAEMON_UNAVAILABLE"
	CodeLocalAPIStarting  = "LOCAL_API_STARTING"
	CodeControllerOffline = "CONTROLLER_OFFLINE"
	CodeExecStartTimeout  = "EXEC_START_TIMEOUT"
	CodeInternal          = "INTERNAL"
)

Error codes aligned with EdgeletAPI v1 and CLI exit mapping.

View Source
const (
	ExitSuccess           = 0
	ExitInternal          = 1
	ExitInvalidArgument   = 2
	ExitUnauthorized      = 3
	ExitNotFound          = 4
	ExitConflict          = 5
	ExitNotImplemented    = 6
	ExitDaemonUnavailable = 10
)

Variables

View Source
var ErrHumanOutputWritten = errors.New("cli: human output already written")

ErrHumanOutputWritten marks failures whose human-mode message was already printed to stderr.

Functions

func ExitCodeForCode

func ExitCodeForCode(code string) int

ExitCodeForCode maps API/CLI error codes to process exit codes.

func ExitCodeForError

func ExitCodeForError(err error) int

ExitCodeForError resolves an exit code from any error, honoring ExitCoder.

func MapAPIError

func MapAPIError(err error) error

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

type CLIError struct {
	Code    string
	Message string
	Err     error
}

CLIError is a typed CLI failure with code and exit mapping.

func NewCLIError

func NewCLIError(code, message string, err error) *CLIError

NewCLIError builds a CLIError with normalized code.

func NewDisplayedCLIError

func NewDisplayedCLIError(code, message string) *CLIError

NewDisplayedCLIError builds a CLIError whose message was already written to stderr.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) ExitCode

func (e *CLIError) ExitCode() int

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

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

type ExitCoder

type ExitCoder interface {
	error
	ExitCode() int
}

ExitCoder allows errors to specify a process exit code.

Jump to

Keyboard shortcuts

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