cli

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 24 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 cli implements the expirely command line: it parses arguments, writes results to stdout and errors to stderr, and returns the process exit code instead of calling os.Exit, so tests drive it through Run.

Output is JSON when --json is set or stdout is not a terminal, and text otherwise. Help is always text.

Index

Constants

View Source
const (
	ExitOK          = 0
	ExitFindings    = 1
	ExitUsage       = 2
	ExitFailure     = 3
	ExitInterrupted = 130
)

Exit codes returned by Run, in order of precedence when a scan has several outcomes: ExitFindings when any certificate is expired or expiring, then ExitFailure when any target could not be read. ExitInterrupted, 128 plus SIGINT as shells report it, means the run was stopped before it ended and printed no results.

View Source
const (
	CodeInvalidFlag        = "invalid_flag"
	CodeInvalidTarget      = "invalid_target"
	CodeMissingArguments   = "missing_arguments"
	CodeFileUnreadable     = "file_unreadable"
	CodeInvalidCAFile      = "invalid_ca_file"
	CodeAWSNotConfigured   = "aws_not_configured"
	CodeAWSAccessDenied    = "aws_access_denied"
	CodeAWSRequestFailed   = "aws_request_failed"
	CodeGCPNotConfigured   = "gcp_not_configured"
	CodeGCPAccessDenied    = "gcp_access_denied"
	CodeGCPComputeDisabled = "gcp_compute_disabled"
	CodeInterrupted        = "interrupted"
	CodeGCPRequestFailed   = "gcp_request_failed"
	CodeOutputFailed       = "output_failed"
)

Error codes are part of the public contract: scripts and agents match on them, so a code is never renamed or reused for a different failure. Every code is listed in docs/reference/error-codes.mdx.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, args []string, s Streams) int

Run executes expirely with args, which exclude the program name, and returns the exit code. Help goes to stdout and exits ExitOK; errors go to stderr and exit with the code errorCodes assigns to them. When ctx is done before the work ends, as on Ctrl-C, Run prints no results and returns ExitInterrupted.

Types

type Error

type Error struct {
	Code    string
	Message string
}

Error is a command failure with a stable Code from errorCodes and a Message for people.

func (*Error) Error

func (e *Error) Error() string

type Streams

type Streams struct {
	Stdin            io.Reader
	Stdout           io.Writer
	Stderr           io.Writer
	StdoutIsTerminal bool
	StderrIsTerminal bool
	Style            ui.Style
	Getenv           func(string) string
	// NewACM builds the ACM client of expirely aws; nil builds the real
	// one from the AWS configuration. Tests set it to a fake.
	NewACM func(ctx context.Context, profile, region string) (acm.API, string, error)
	// NewGCP builds the Compute client of expirely gcp; nil builds the real
	// one from Application Default Credentials. Tests point it at a fake.
	NewGCP func(ctx context.Context) (*gcp.Service, error)
}

Streams holds the standard streams Run reads from and writes to. StdoutIsTerminal selects text output when --json is not set, and Style is how stdout shows that text; the zero Style is plain. StderrIsTerminal allows a progress spinner on stderr while a scan runs. Getenv reads the environment for agent detection; nil detects no agent.

Jump to

Keyboard shortcuts

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