cli

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
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.

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.

View Source
const Name = "nctl"

Name is the name of the CLI binary.

Variables

This section is empty.

Functions

func GetCmd added in v1.21.0

func GetCmd(kind string, args ...string) string

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

func SetProjectCmd(project string) string

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

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), unless the code was set to ExitOK with WithExitCode.

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