cliutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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 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 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 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