Documentation
¶
Overview ¶
Package cli implements the stacktower command-line interface.
Index ¶
- Constants
- Variables
- func ExitCodeForError(err error) int
- func NewSystemError(message string, hint string) error
- func NewUserError(message string, hint string) error
- func WrapSystemError(cause error, message string, hint string) error
- func WrapUserError(cause error, message string, hint string) error
- type CLI
- type CLIError
- type ErrorKind
- type VulnError
Constants ¶
const ( LogDebug = log.DebugLevel LogInfo = log.InfoLevel )
Log levels exported for use in main.go.
const ( // ExitCodeFailure is a generic runtime failure. ExitCodeFailure = 1 // ExitCodeUsage indicates invalid input/usage from the caller. ExitCodeUsage = 2 // ExitCodeVuln signals that new vulnerabilities were detected (used by diff --fail-on-vuln). ExitCodeVuln = 3 // ExitCodeInterrupted follows shell convention for SIGINT/SIGTERM. ExitCodeInterrupted = 130 )
const ( FormatText = "text" FormatJSON = "json" )
Format constants for the "text | json" output switch used by analysis commands (why, stats, diff, sbom). Centralizing these keeps help text and default values aligned across commands.
Variables ¶
var ErrCancelled = errors.New("operation cancelled")
var ErrNotLoggedIn = errors.New("not logged in")
ErrNotLoggedIn is a sentinel used by loadGitHubSession when no session exists. Checked structurally via errors.Is in the login flow.
Functions ¶
func ExitCodeForError ¶
ExitCodeForError maps errors to stable process exit codes.
Mapping:
- nil → 0
- context.Canceled → 130 (SIGINT/SIGTERM convention)
- VulnError → 3 (diff --fail-on-vuln)
- CLIError{Kind:User} → 2 (usage/input errors)
- anything else → 1 (generic runtime failure)
Note: context.DeadlineExceeded intentionally maps to 1 (runtime failure), not 130, because a timeout is typically a system/network condition rather than a user-initiated interrupt.
func NewSystemError ¶
NewSystemError constructs an execution/network/runtime error with optional hint.
func NewUserError ¶
NewUserError constructs a usage/input error with an optional actionable hint.
func WrapSystemError ¶
WrapSystemError wraps a cause as an execution/network/runtime error.
Types ¶
type CLI ¶
CLI holds shared state for all commands.
NOTE: ui.SetQuiet and observability.Set*Hooks are package-global, so only one CLI instance can be active per process. This is fine for a CLI binary but means tests that construct multiple CLI values cannot run in parallel with different quiet/log configurations. New returns an error on a second call to catch accidental double-initialization (e.g. a test constructing two CLI values without coordinating globals).
func New ¶
New creates a new CLI instance with a default logger. Registers observability hooks for pipeline and security events.
Only one CLI instance may be created per process; calling New a second time returns an error. The stacktower binary only creates one CLI, and tests that need to validate behavior across multiple configurations should do so through the single instance rather than constructing several.
func (*CLI) AttachOrderingSpinner ¶ added in v1.6.0
AttachOrderingSpinner wires a spinner to receive ordering-progress updates via the pipeline hook. Pass nil (e.g. in a defer) to detach. The hook only ever knows about the ui.Spinner through this seam; the ordering algorithm itself stays free of CLI/TTY dependencies.
func (*CLI) RootCommand ¶
RootCommand creates the root cobra command with all subcommands registered.
func (*CLI) SetLogLevel ¶
SetLogLevel updates the logger's level.