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
- func ActionLogFromContext(ctx context.Context) *actionlog.Logger
- func ConsoleScope(cmd *cobra.Command, rc *aktctx.Context) (organization, project string)
- func Debug(cmd *cobra.Command, msg string)
- func Debugf(cmd *cobra.Command, format string, args ...interface{})
- func ExitCode(err error) int
- func IsDebug(cmd *cobra.Command) bool
- func IsQuiet(cmd *cobra.Command) bool
- func IsTTY() bool
- func IsVerbose(cmd *cobra.Command) bool
- func SelectedContextName(cmd *cobra.Command, manager *aktctx.Manager) string
- func Status(cmd *cobra.Command, msg string)
- func Statusf(cmd *cobra.Command, format string, args ...interface{})
- func UserFacingError(err error) string
- func Verbose(cmd *cobra.Command, msg string)
- func Verbosef(cmd *cobra.Command, format string, args ...interface{})
- func Verbosity(cmd *cobra.Command) int
- func WithActionLog(ctx context.Context, l *actionlog.Logger) context.Context
- type CLIError
Constants ¶
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 ¶
ActionLogFromContext returns the *actionlog.Logger stored in the context, or nil if none was set.
func ConsoleScope ¶ added in v1.1.0
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 ExitCode ¶
ExitCode extracts the exit code from an error. If the error is a *CLIError, its Code is returned. Otherwise returns ExitGeneral (1).
func SelectedContextName ¶ added in v0.0.3
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 ¶
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 UserFacingError ¶ added in v0.0.5
UserFacingError renders err for terminal display while leaving the error value itself untouched for exit-code classification and action logging.
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>