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 ¶
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 or a cloud command could not read every region. ExitInterrupted, 128 plus SIGINT as shells report it, means the run was stopped before it ended and printed no results.
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 ¶
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 ¶
Error is a command failure with a stable Code from errorCodes and a Message for people.
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 opens the AWS account expirely tls aws reads; nil opens the real
// one from the AWS configuration. Tests set it to a fake.
NewACM func(ctx context.Context, profile, region string) (acm.Account, error)
// NewGCP builds the Compute client of expirely tls 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.