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 ¶
- func EncodeStdout(format string, payload any) (handled bool, err error)
- func PositionalAt(c *cli.Context, flagName string, index int) string
- func PositionalSlot(c *cli.Context, flagName string, priorFlags ...string) string
- func RequestedCluster(c *cli.Context) string
- func ResolveClusterOrList(ctx context.Context, cfg aws.Config, c *cli.Context) (clusterName string, listed bool, err error)
- func SecondPositional(c *cli.Context, flagName string) string
- func SetupAWS(c *cli.Context) (context.Context, context.CancelFunc, aws.Config, error)
- func SetupAWSStrict(c *cli.Context) (context.Context, context.CancelFunc, aws.Config, error)
- func SetupAWSWithTimeout(c *cli.Context, defaultTimeout time.Duration) (context.Context, context.CancelFunc, aws.Config, error)
- func WithSpinner(category, successMsg string, fn func() error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeStdout ¶
EncodeStdout writes payload to stdout as JSON or YAML based on format. For any other format value, returns ErrUnknownFormat so the caller can fall through to its table renderer.
func PositionalAt ¶
PositionalAt returns the value of flagName, or the non-flag positional argument at index (0-indexed) if the flag is not set. Does NOT account for prior flags absorbing positional slots — use PositionalSlot for that.
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: first positional arg if present, otherwise --cluster.
func ResolveClusterOrList ¶
func ResolveClusterOrList(ctx context.Context, cfg aws.Config, c *cli.Context) (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 SecondPositional ¶
SecondPositional returns the value of flagName, or the second non-flag positional argument if the flag is not set. Use PositionalSlot for commands where prior slots may be supplied via flags (which shifts the positional indices).
func SetupAWS ¶
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 ¶
SetupAWSStrict is like SetupAWS but uses ValidateAWSCredentials and prints the credential help message on failure (used by destructive commands).
func SetupAWSWithTimeout ¶
func SetupAWSWithTimeout(c *cli.Context, defaultTimeout time.Duration) (context.Context, context.CancelFunc, aws.Config, error)
SetupAWSWithTimeout is like SetupAWS but falls back to defaultTimeout when c.Duration("timeout") is zero.
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.