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 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 Status(cmd *cobra.Command, msg string)
- func Statusf(cmd *cobra.Command, format string, args ...interface{})
- 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 ExitCode ¶
ExitCode extracts the exit code from an error. If the error is a *CLIError, its Code is returned. Otherwise returns ExitGeneral (1).
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.
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>