cli

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagedByAnnotation = "app.kubernetes.io/managed-by"
	Name                = "nctl"
)
View Source
const (
	// ExitOK indicates that the program exited successfully.
	ExitOK = 0
	// ExitError indicates that the program exited unsuccessfully
	// but gives no extra context as to what the failure was.
	ExitError = 1
	// ExitUsageError indicates that the program exited unsuccessfully
	// because it was used incorrectly.
	//
	// Examples: a required argument was omitted or an invalid value
	// was supplied for a flag.
	ExitUsageError = 80
	// ExitForbidden indicates that the program exited unsuccessfully
	// because the user isn't authorized to perform the requested action.
	ExitForbidden = 83
	// ExitInternalError indicates that the program exited unsuccessfully
	// because of a problem in its own code.
	//
	// Used instead of 1 when the problem is known to be with the program's
	// code or dependencies.
	ExitInternalError = 100
	// ExitUnavailable indicates that the program exited unsuccessfully
	// because a service it depends on was not available.
	//
	// Examples: A local daemon or remote service did not respond, a connection
	// was closed unexpectedly, an HTTP service responded with 503.
	ExitUnavailable = 101
)

Exit codes following the square/exit convention. See https://pkg.go.dev/github.com/square/exit#readme-the-codes for details.

Variables

This section is empty.

Functions

func IsManagedBy

func IsManagedBy(annotations map[string]string) bool

Types

type Error

type Error struct {
	// Err is the underlying error being wrapped.
	Err error
	// Code is the exit code for this error. When zero, ExitCode defaults to ExitError (1).
	Code int
	// Context provides additional key-value metadata about the error (e.g., "Organization": "foo").
	Context map[string]string
	// Available lists valid options that could have been used.
	Available []string
	// Suggestions provides recommended commands or actions to fix the error.
	Suggestions []string
}

Error wraps an error with additional context for user-friendly display. It implements [kong.ExitCoder] to provide semantic exit codes.

func ErrorWithContext

func ErrorWithContext(err error) *Error

ErrorWithContext wraps an existing error with contextual information. Returns nil if err is nil.

func (*Error) Error

func (e *Error) Error() string

Error returns the full formatted error for display to the user, including context, available options, and suggestions.

func (*Error) ExitCode

func (e *Error) ExitCode() int

ExitCode returns the exit code for this error, satisfying [kong.ExitCoder]. When Code is zero, it defaults to ExitError (1).

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error for errors.Is / errors.As support.

func (*Error) WithAvailable

func (e *Error) WithAvailable(items ...string) *Error

WithAvailable adds available options to the error.

func (*Error) WithContext

func (e *Error) WithContext(key, value string) *Error

WithContext adds a key-value pair to the error context.

func (*Error) WithExitCode

func (e *Error) WithExitCode(code int) *Error

WithExitCode sets the exit code for the error.

func (*Error) WithSuggestions

func (e *Error) WithSuggestions(suggestions ...string) *Error

WithSuggestions adds suggested actions to the error.

Jump to

Keyboard shortcuts

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