Documentation
¶
Overview ¶
Package runner provides shared CLI command primitives so that every command's run* function doesn't re-implement context+awsconfig+credential setup, the "no cluster specified" fallback, and json/yaml encoding.
Index ¶
- Variables
- func EncodeStdout(format string, payload any) (handled bool, err error)
- func ParseFilters(filters []string) map[string]string
- func PositionalSlot(cmd *cli.Command, flagName string, priorFlags ...string) string
- func RequestedCluster(cmd *cli.Command) string
- func ResolveClusterOrList(ctx context.Context, cfg aws.Config, cmd *cli.Command) (clusterName string, listed bool, err error)
- func SetupAWS(ctx context.Context, cmd *cli.Command) (context.Context, context.CancelFunc, aws.Config, error)
- func SetupAWSStrict(ctx context.Context, cmd *cli.Command) (context.Context, context.CancelFunc, aws.Config, error)
- func SetupAWSWithTimeout(ctx context.Context, cmd *cli.Command, defaultTimeout time.Duration) (context.Context, context.CancelFunc, aws.Config, error)
- func ValidateFormat(format string, allowed []string) error
- func Watch(cmd *cli.Command, fn func() error) error
- func WithSpinner(category, successMsg string, fn func() error) error
Constants ¶
This section is empty.
Variables ¶
var ( // FormatsStandard is the common set for list/describe/encode commands. FormatsStandard = []string{"table", "json", "yaml", "plain"} // FormatsWithTree adds the cluster-list-only hierarchical tree renderer. FormatsWithTree = []string{"table", "json", "yaml", "plain", "tree"} // FormatsTableJSON is for commands that only emit a table or a JSON summary // (e.g. nodegroup update's run summary). FormatsTableJSON = []string{"table", "json"} )
Output-format presets for ValidateFormat. Commands pass the set they can actually render so an unknown value fails loudly instead of silently falling through to the table renderer.
Functions ¶
func EncodeStdout ¶
EncodeStdout writes payload to stdout as JSON or YAML based on format.
"plain" is special-cased: it switches the UI layer into uncolored, tab-separated table rendering and returns handled=false, so the caller's table renderer produces grep/awk-friendly output.
For any other format value it returns handled=false so the caller can fall through to its table renderer.
func ParseFilters ¶ added in v0.7.0
ParseFilters parses repeated key=value --filter flag values into a map. Tokens without "=" are ignored.
func PositionalSlot ¶
PositionalSlot returns the value of flagName, or — when flagName is unset — the positional argument that fills its slot, accounting for prior slots that may have been satisfied by flags.
priorFlags lists, in order, the flag name for each prior positional slot. An entry may be "" to mean "this prior slot has no flag and is always positional". For each prior flag name that IS set on the context, this helper subtracts 1 from the expected positional index, so flags and positionals can be mixed freely.
Example: a command with slot order (cluster, addon, version) where the cluster has --cluster, the addon has --addon, and the version has --version:
cluster := PositionalSlot(c, "cluster") // slot 0 addon := PositionalSlot(c, "addon", "cluster") // slot 1 version := PositionalSlot(c, "version", "cluster", "addon") // slot 2
Invocation `--addon=foo my-cluster v1.2.3` yields cluster="my-cluster", addon="foo" (from flag), version="v1.2.3" — the version's positional index is shifted from 2 down to 1 because --addon consumed a slot.
func RequestedCluster ¶
RequestedCluster returns the cluster name requested by the user: --cluster when explicitly set (so positionals can fill later slots), otherwise the first positional arg.
func ResolveClusterOrList ¶
func ResolveClusterOrList(ctx context.Context, cfg aws.Config, cmd *cli.Command) (clusterName string, listed bool, err error)
ResolveClusterOrList resolves the requested cluster name. If no cluster was requested, it prints "No cluster specified. Available clusters:" plus the cluster table and returns listed=true so the caller can short-circuit.
func SetupAWS ¶
func SetupAWS(ctx context.Context, cmd *cli.Command) (context.Context, context.CancelFunc, aws.Config, error)
SetupAWS opens a context with the command's timeout, loads the AWS config, and checks credentials. On error, the returned cancel is nil and the internal context has already been cancelled.
func SetupAWSStrict ¶
func SetupAWSStrict(ctx context.Context, cmd *cli.Command) (context.Context, context.CancelFunc, aws.Config, error)
SetupAWSStrict is like SetupAWS but uses ValidateAWSCredentials and prints the credential help message on failure (used by destructive commands).
func SetupAWSWithTimeout ¶
func SetupAWSWithTimeout(ctx context.Context, cmd *cli.Command, defaultTimeout time.Duration) (context.Context, context.CancelFunc, aws.Config, error)
SetupAWSWithTimeout is like SetupAWS but falls back to defaultTimeout when cmd.Duration("timeout") is zero.
func ValidateFormat ¶ added in v0.7.0
ValidateFormat returns an error when format is not one of allowed. Matching is case-insensitive and an empty value is treated as valid (callers default it to "table"). Without this, runner.EncodeStdout returns handled=false for an unrecognized format and every caller falls through to its table renderer, so a typo like `-o jsom` silently prints a human table and exits 0. (REF-48)
func Watch ¶ added in v0.7.0
Watch reruns fn every --watch-interval until interrupted when --watch is set; otherwise it runs fn once. On an interactive terminal the screen is cleared between iterations (top-style); when output is piped, iterations append instead. fn should perform the full fetch+render cycle so every iteration shows fresh data.
func WithSpinner ¶
WithSpinner runs fn between starting and stopping a spinner for category. On error, the spinner is stopped without a success message.
Types ¶
This section is empty.