cli

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 25 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 is the estimate command (vision docs/specs/2026-10-10-savings-estimate-design.md §3, §8): the options, the accounts, the three phases with their progress, the reports and the summary. Exit code 0; 1 when AWS refuses (credentials, an organization call); 2 on a bad option (accounts given that cannot be estimated too). AWS comes through EstimateAWS (aws.go wires the SDK; the tests, fakes).

Ports manager packages/estimate/src/cli.ts (EstimateAws, CliDeps, main).

Index

Constants

View Source
const Interrupted = 130

Interrupted is the exit code of a run stopped by Ctrl-C (its context cancelled): 128 + SIGINT, what a shell reports for the Node estimate, killed by the signal. Nothing is said, no report is written.

Variables

This section is empty.

Functions

func Main

func Main(args []string, deps Deps) (code int)

Main runs the estimate command with its arguments (those after "estimate") and returns its exit code: 0; 2 with the message and the usage for a bad option, or the message for accounts given that cannot be estimated (known once AWS answered); 1 with `name: message` for anything else (credentials that do not work, an organization call AWS refuses), on one line, AWS's words without the SDK's wrappers (awserr.Cause), and for an SSO token error a second line, `Run aws sso login --profile <profile> and try again.`; Interrupted when the context is cancelled. --help prints the usage (exit code 0). A panic is said as `Error: <its value>`, exit code 1, without a goroutine dump (F6: Node says `TypeError: …` and exits 1); a worker's is its item's error (limit.Map).

func Plural added in v0.7.0

func Plural(n int, word string) string

Plural is "1 account" or "5 accounts" at a time.

func StatusOf

func StatusOf(out io.Writer) progress.Status

StatusOf is the Status of out when it is a terminal (the command's stdout), else nil: a line per account or region.

func Terminal

func Terminal(w io.Writer) progress.Status

Terminal is the Status of a terminal written to w: Update writes "\r\x1b[2K\x1b[?7l", the line and "\x1b[?7h" (Node's sequence, autowrap off while the line is drawn: Ruling P18), End the same and a newline. It only writes: it never calls back into the view that calls it.

Types

type Deps

type Deps struct {
	// Context is the run's: cancelled on Ctrl-C (nil: never).
	Context   context.Context
	Now       func() time.Time
	CacheRoot string
	Log       func(line string)
	Error     func(line string)
	// AWS is each profile's: an account is read with the profile reaching it.
	AWS func(o options.Options, profile string) EstimateAWS
	// WriteFile writes a report (nil: the file is written, its directory made).
	WriteFile func(path, text string) error
	// Status is a terminal's: each phase's progress on one line rewritten in place (nil: a line per account or region).
	Status progress.Status
	// Version is the JSON report's tool version.
	Version string
}

Deps are the command's dependencies (Node's CliDeps).

type EstimateAWS

type EstimateAWS struct {
	Accounts     accounts.Ports
	RegionsOf    func(ctx context.Context, account string, creds *aws.Credentials) ([]string, error)
	PortsOf      func(ctx context.Context, account, region string, creds *aws.Credentials) (discover.RegionPorts, error)
	CloudWatchOf func(ctx context.Context, account, region string, creds *aws.Credentials) (metrics.CloudWatchPort, error)
	Prices       func(cache prices.Cache) PriceBook
}

EstimateAWS is one profile's AWS (Node's EstimateAws): the accounts it reaches, an account's enabled regions, the ports of an account's region, its CloudWatch, and the price book. creds nil: the profile's own.

func AWSOf

func AWSOf(_ options.Options, profile string) EstimateAWS

AWSOf is one profile's AWS (several are given with --profile a,b, each reaching its accounts): its shared configuration, read now; its credentials resolved when a call needs them. A profile that cannot be loaded (missing from the config) fails every call with the SDK's message: the first, who the profile is, gives exit code 1.

type PriceBook

type PriceBook struct {
	Hourly  func(ctx context.Context, region string, item stopped.Item, d prices.Discounts) (*float64, error)
	Failure func() string
}

PriceBook is the price book the estimate reads: an item's hourly price in a region, net of the discounts (nil: no price), and the first price lookup AWS refused, said as `name: message` (Failure nil or "": none), so the unpriced workloads say why.

Jump to

Keyboard shortcuts

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