cliutil

package
v1.1.2 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: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cliutil provides shared CLI utilities (error types, status helpers, verbosity) that are safe to import from both internal/cli and internal/cli/chain without creating import cycles.

Index

Constants

View Source
const (
	ExitSuccess        = 0
	ExitGeneral        = 1
	ExitUsage          = 2
	ExitConfig         = 3
	ExitConnection     = 4
	ExitTransaction    = 5
	ExitAuth           = 6
	ExitStore          = 7
	ExitPluginNotFound = 127
)

Exit codes per SPEC §11.2.

Variables

This section is empty.

Functions

func ActionLogFromContext

func ActionLogFromContext(ctx context.Context) *actionlog.Logger

ActionLogFromContext returns the *actionlog.Logger stored in the context, or nil if none was set.

func ConsoleScope added in v1.1.0

func ConsoleScope(cmd *cobra.Command, rc *aktctx.Context) (organization, project string)

ConsoleScope returns the Console organization and project this invocation acts in (SPEC §7.1.1): a --console-organization or --console-project flag given on the command line, then the resolved context, where AKT_CONSOLE_ORGANIZATION and AKT_CONSOLE_PROJECT already override the stored selection, then those variables alone when no context resolved. An explicitly empty flag clears the selection for this invocation.

func Debug

func Debug(cmd *cobra.Command, msg string)

Debug writes a message to stderr only when -vv is active.

func Debugf

func Debugf(cmd *cobra.Command, format string, args ...interface{})

Debugf is a formatted variant of Debug.

func ExitCode

func ExitCode(err error) int

ExitCode extracts the exit code from an error. If the error is a *CLIError, its Code is returned. Otherwise returns ExitGeneral (1).

func IsDebug

func IsDebug(cmd *cobra.Command) bool

IsDebug returns true when -vv is set (verbosity >= 2).

func IsQuiet

func IsQuiet(cmd *cobra.Command) bool

IsQuiet returns true when --quiet is set (verbosity < 0).

func IsTTY

func IsTTY() bool

IsTTY returns true if stdout is connected to a terminal.

func IsVerbose

func IsVerbose(cmd *cobra.Command) bool

IsVerbose returns true when -v or -vv is set (verbosity >= 1).

func SelectedContextName added in v0.0.3

func SelectedContextName(cmd *cobra.Command, manager *aktctx.Manager) string

SelectedContextName returns the one context targeted by this invocation. An explicitly supplied global flag wins over AKT_CONTEXT; the manager then applies its current-context and sole-context fallbacks.

func Status

func Status(cmd *cobra.Command, msg string)

Status writes an informational message to stderr. Suppressed when --quiet is set or stdout is not a TTY. Use for progress messages, confirmations, and operational feedback.

func Statusf

func Statusf(cmd *cobra.Command, format string, args ...interface{})

Statusf is a formatted variant of Status.

func UserFacingError added in v0.0.5

func UserFacingError(err error) string

UserFacingError renders err for terminal display while leaving the error value itself untouched for exit-code classification and action logging.

func Verbose

func Verbose(cmd *cobra.Command, msg string)

Verbose writes a message to stderr only when -v (or -vv) is active.

func Verbosef

func Verbosef(cmd *cobra.Command, format string, args ...interface{})

Verbosef is a formatted variant of Verbose.

func Verbosity

func Verbosity(cmd *cobra.Command) int

Verbosity reads the counted -v flag. Returns -1 when --quiet is set, 0 for default, 1 for -v, 2 for -vv. Safe to call even when flags are not registered (returns 0).

func WithActionLog

func WithActionLog(ctx context.Context, l *actionlog.Logger) context.Context

WithActionLog stores an *actionlog.Logger in the context.

Types

type CLIError

type CLIError struct {
	Code       int    // exit code (see constants above)
	Message    string // user-facing summary (what happened)
	Cause      error  // underlying error (may be nil)
	Context    string // what was being attempted
	Suggestion string // actionable next step
}

CLIError is a structured error with user-facing context per SPEC §11.1. Every CLIError renders as a three-part message:

Error: <what happened>
  Context:    <what was being attempted>
  Suggestion: <actionable next step>

func ErrAuth

func ErrAuth(msg string, cause error) *CLIError

func ErrConfig

func ErrConfig(msg string, suggestion string) *CLIError

func ErrConnection

func ErrConnection(endpoint string, cause error) *CLIError

func ErrTransaction

func ErrTransaction(msg string, cause error) *CLIError

func ErrUsage

func ErrUsage(msg string, cause error) *CLIError

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

Jump to

Keyboard shortcuts

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