Documentation
¶
Index ¶
- Constants
- func GetCmd(kind string, args ...string) string
- func SetProjectCmd(project string) string
- type Error
- func (e *Error) Error() string
- func (e *Error) ExitCode() int
- func (e *Error) Unwrap() error
- func (e *Error) WithAvailable(items ...string) *Error
- func (e *Error) WithContext(key, value string) *Error
- func (e *Error) WithExitCode(code int) *Error
- func (e *Error) WithSuggestions(suggestions ...string) *Error
Constants ¶
const ( // LoginCmd logs in to the API. LoginCmd = Name + " auth login" // WhoAmICmd shows the current session. WhoAmICmd = Name + " auth whoami" // GetProjectsCmd lists the projects. GetProjectsCmd = Name + " get projects" )
Command lines suggested to users in hints and error messages.
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 // 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.
const Name = "nctl"
Name is the name of the CLI binary.
Variables ¶
This section is empty.
Functions ¶
func GetCmd ¶ added in v1.21.0
GetCmd returns the command line getting resources of kind. The kind is lowercased, so that it can be passed as it is.
func SetProjectCmd ¶ added in v1.21.0
SetProjectCmd returns the command line setting the project, with a placeholder when project is empty.
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),
// unless the code was set to ExitOK with WithExitCode.
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
// contains filtered or unexported fields
}
Error wraps an error with additional context for user-friendly display. It implements [kong.ExitCoder] to provide semantic exit codes.
func ErrorWithContext ¶
ErrorWithContext wraps an existing error with contextual information. Returns nil if err is nil.
func (*Error) Error ¶
Error returns the full formatted error for display to the user, including context, available options, and suggestions.
func (*Error) ExitCode ¶
ExitCode returns the exit code for this error, satisfying [kong.ExitCoder]. When Code is zero, it defaults to ExitError (1), unless the code was set to ExitOK with WithExitCode.
func (*Error) WithAvailable ¶
WithAvailable adds available options to the error.
func (*Error) WithContext ¶
WithContext adds a key-value pair to the error context.
func (*Error) WithExitCode ¶
WithExitCode sets the exit code for the error.
func (*Error) WithSuggestions ¶
WithSuggestions adds suggested actions to the error.