cmdutil

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoServer = errors.New("no server configured")

ErrNoServer is returned when a command needs a server but none was given on the command line, in the environment or in a saved connection.

Functions

func CleanAPIError added in v0.36.0

func CleanAPIError(err error) string

CleanAPIError strips the transport framing the REST client wraps around non-2xx responses ("unexpected status code: 400: …") and returns just the server's error message.

func CleanErr added in v0.37.0

func CleanErr(err error) error

CleanErr wraps err so its text is CleanAPIError's (the server's message without the REST client's framing) while errors.As still finds the underlying HTTPError, letting FormatError add the status and a hint.

func ClientFlags added in v0.37.0

func ClientFlags(short bool) []cli.Flag

ClientFlags returns the flags that choose the server a command talks to: an explicit --server and --token, else the alias (default "default") from the config file's client.connection section. Commands that already use -s, -t or -a for something else take them without short names.

func Describe added in v0.37.0

func Describe(err error) string

Describe is FormatError without the "Error: " prefix, for warnings and per-item failures printed while a command carries on.

func ExplicitServerAddr added in v0.34.0

func ExplicitServerAddr(cmd *cli.Command) *config.ServerAddr

ExplicitServerAddr returns the server the user explicitly targeted via a --server and --token pair (flag or env), or via an --alias that resolves in the config file. It returns nil when neither is given, so inside a space callers can fall back to the server that owns the space.

Note the both-non-empty rule for the flags: spaces always have KNOT_SERVER set to the owning server's URL, so a token alone must never count as an explicit target. An --alias is only honoured when actually given on the command line — the "default" alias is never consulted implicitly, so a config file carried into a space cannot silently redirect tunnels.

func FormatError added in v0.37.0

func FormatError(err error) string

FormatError turns an error from a command into the single line shown on the terminal: "Error: <what failed>: <why>. <what to do next>". It recognises the API client's HTTPError (status code and server message) and the usual network failures (connection refused, unknown host, certificate problems, timeouts) anywhere in the error chain and rewrites them in plain words, keeping whatever context the command wrapped around them.

func GetClient

func GetClient(cmd *cli.Command) (*apiclient.ApiClient, error)

func GetServerAddr added in v0.25.0

func GetServerAddr(cmd *cli.Command) *config.ServerAddr

func ParseCustomFields added in v0.38.0

func ParseCustomFields(rawFields []string) ([]apiclient.CustomFieldValue, error)

ParseCustomFields parses --custom-field values given as name=value.

func WebSocketError added in v0.37.0

func WebSocketError(what string, resp *http.Response, err error) error

WebSocketError describes a failed websocket dial. When the server answered the handshake with an error status it becomes an HTTPError, so the status is reported (and hinted) like any other API failure.

Types

type ExitCodeError added in v0.38.0

type ExitCodeError struct {
	Code int
	Err  error
}

ExitCodeError ends the CLI with a specific exit status, such as that of a command run in a space, after printing its message.

func (*ExitCodeError) Error added in v0.38.0

func (e *ExitCodeError) Error() string

func (*ExitCodeError) Unwrap added in v0.38.0

func (e *ExitCodeError) Unwrap() error

Jump to

Keyboard shortcuts

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