cmdutil

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCodeForError

func ExitCodeForError(err error) int

ExitCodeForError maps error types to process exit codes:

  • nil or CancelError -> 0
  • FlagError or NotFoundError -> 2
  • RateLimitError -> 5
  • everything else -> 1

func OpenBrowser added in v0.4.0

func OpenBrowser(url string) error

OpenBrowser opens the given URL in the user's default browser. It uses "open" on macOS, "xdg-open" on Linux, and "cmd /c start" on Windows.

func ResolveHost added in v0.4.0

func ResolveHost(cmd *cobra.Command, cfg config.Config) string

ResolveHost resolves the target host using the priority chain: --host flag > KH_HOST env > cfg.DefaultHost > "app.keeperhub.com".

Types

type CancelError

type CancelError struct {
	Err error
}

CancelError indicates a user-initiated cancellation (e.g., answering "no" to a confirmation prompt). The process exits 0 with no error output.

func (CancelError) Error

func (e CancelError) Error() string

func (CancelError) Unwrap

func (e CancelError) Unwrap() error

type Factory

type Factory struct {
	// AppVersion is the binary version string, injected at build time via ldflags.
	AppVersion string

	// Config returns the parsed application configuration.
	Config func() (config.Config, error)

	// HTTPClient returns a configured KeeperHub HTTP client for API requests.
	// The client automatically injects version headers and per-host credentials.
	HTTPClient func() (*khhttp.Client, error)

	// BaseURL returns the resolved base URL for API requests, accounting for
	// --host flag, KH_HOST env, and config defaults. Use this instead of
	// ResolveHost when a cobra.Command is not available (e.g. MCP serve mode).
	BaseURL func() string

	// IOStreams provides the standard input/output streams.
	IOStreams *iostreams.IOStreams
}

Factory is the dependency injection container passed to every command. Commands receive a *Factory and call its func fields to obtain dependencies lazily; this allows tests to inject mocks without a full runtime setup.

type FlagError

type FlagError struct {
	Err error
}

FlagError indicates an invalid or missing CLI flag value. The error message is printed without a stack trace and the process exits 2.

func (FlagError) Error

func (e FlagError) Error() string

func (FlagError) Unwrap

func (e FlagError) Unwrap() error

type NotFoundError

type NotFoundError struct {
	Err error
}

NotFoundError wraps a 404 response. Exit code: 2.

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Unwrap

func (e NotFoundError) Unwrap() error

type RateLimitError

type RateLimitError struct {
	Err        error
	RetryAfter time.Duration
}

RateLimitError wraps a 429 response. Exit code: 5.

func (RateLimitError) Error

func (e RateLimitError) Error() string

func (RateLimitError) Unwrap

func (e RateLimitError) Unwrap() error

type SilentError

type SilentError struct {
	Err error
}

SilentError signals that the error message has already been printed and the process should exit non-zero without printing anything further.

func (SilentError) Error

func (e SilentError) Error() string

func (SilentError) Unwrap

func (e SilentError) Unwrap() error

Jump to

Keyboard shortcuts

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