Documentation
¶
Index ¶
- func AddPaginationFlags(cmd *cobra.Command, what string)
- func AddTimeRangeFlags(cmd *cobra.Command, defaultRange time.Duration)
- func AddWaitFlags(cmd *cobra.Command, what string, timeout, pollInterval time.Duration)
- func AnyFlagChanged(cmd *cobra.Command, flags []string) bool
- func ApplyIPs(existing []string, changes *IPChanges) []string
- func ApplyLabels(existing []*commonv1.KeyValue, changes *LabelChanges) []*commonv1.KeyValue
- func ApplyListChanges(existing []string, changes *ListChanges) []string
- func ConfirmAction(force bool, w io.Writer, prompt string) bool
- func ExactArgs(n int, usage string) cobra.PositionalArgs
- func FetchPages[T any](cmd *cobra.Command, ...) ([]T, *string, error)
- func IsUUID(s string) bool
- func NextCronRun(cronExpr string) (time.Time, bool)
- func ParseDateEndOfDay(s string) (time.Time, error)
- func ParseTimeFlag(s string, now time.Time) (time.Time, error)
- func ParseUntilFlag(s string, now time.Time) (time.Time, error)
- func PollUntilDone[T any](ctx context.Context, timeout, pollInterval time.Duration, what string, ...) (T, error)
- func ReadPastTimeRange(cmd *cobra.Command, now time.Time, defaultRange time.Duration) (since, until time.Time, err error)
- func ReadTimeRange(cmd *cobra.Command, now time.Time) (since, until *timestamppb.Timestamp, err error)
- type IPChanges
- type LabelChanges
- type ListChanges
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPaginationFlags ¶ added in v0.31.0
AddPaginationFlags registers the --page-size and --page-token flags used by list commands. what names the listed resources in the flag help.
func AddTimeRangeFlags ¶ added in v0.36.0
AddTimeRangeFlags registers the --since and --until flags read by ReadPastTimeRange. defaultRange is the length of the range when --since is omitted, and is shown in the help text.
func AddWaitFlags ¶ added in v0.31.0
AddWaitFlags registers the --wait, --wait-timeout and hidden --wait-poll-interval flags. what describes the awaited condition (e.g. "the cluster to become healthy").
func AnyFlagChanged ¶ added in v0.16.0
AnyFlagChanged reports whether any flag in the given list was set by the user.
func ApplyIPs ¶ added in v0.10.1
ApplyIPs applies IPChanges to an existing IP list and returns a new sorted slice. The input slice is not modified. Removing an IP that does not exist is a silent no-op.
func ApplyLabels ¶ added in v0.10.1
func ApplyLabels(existing []*commonv1.KeyValue, changes *LabelChanges) []*commonv1.KeyValue
ApplyLabels applies LabelChanges to an existing label set and returns a new slice sorted by key. The input slice is not modified. Removing a key that does not exist is a silent no-op.
func ApplyListChanges ¶ added in v0.30.0
func ApplyListChanges(existing []string, changes *ListChanges) []string
ApplyListChanges applies ListChanges to an existing list and returns a new sorted slice. The input slice is not modified. Removing an entry that does not exist is a silent no-op.
func ConfirmAction ¶
ConfirmAction prompts the user for confirmation. Returns true if they confirm. If force is true, skips the prompt and returns true. The prompt is written to w.
func ExactArgs ¶
func ExactArgs(n int, usage string) cobra.PositionalArgs
ExactArgs returns a PositionalArgs that requires exactly n args with a descriptive error.
func FetchPages ¶ added in v0.31.0
func FetchPages[T any]( cmd *cobra.Command, fetch func(pageSize *int32, pageToken *string) (items []T, nextPageToken string, err error), ) ([]T, *string, error)
FetchPages runs a paginated list call. Unless --page-size or --page-token is set, it follows next-page tokens and returns all items with a nil next token. Otherwise it performs a single request with the given flags and returns the next page token, if any.
func NextCronRun ¶ added in v0.30.0
NextCronRun returns the next time after now (UTC) at which the cron expression fires. It returns false if the expression cannot be parsed.
func ParseDateEndOfDay ¶ added in v0.31.0
ParseDateEndOfDay parses a YYYY-MM-DD date and returns the last second of that day in UTC, so that the date is inclusive when used as an upper bound.
func ParseTimeFlag ¶ added in v0.31.0
ParseTimeFlag parses a time flag value used as a lower bound. It accepts an RFC3339 timestamp, a date in YYYY-MM-DD format (start of the day in UTC), or a positive duration that is subtracted from now: any Go duration (e.g. "90m", "24h") or a number of days with a "d" suffix (e.g. "7d").
func ParseUntilFlag ¶ added in v0.31.0
ParseUntilFlag is like ParseTimeFlag but for upper bounds: a YYYY-MM-DD date resolves to the end of that day, so that the whole day is included.
func PollUntilDone ¶ added in v0.31.0
func PollUntilDone[T any]( ctx context.Context, timeout, pollInterval time.Duration, what string, poll func(ctx context.Context) (T, bool, error), ) (T, error)
PollUntilDone calls poll immediately and then on every tick until it returns done=true, returns an error, or the timeout expires. what describes the awaited condition in timeout errors (e.g. "space to become ready").
func ReadPastTimeRange ¶ added in v0.36.0
func ReadPastTimeRange(cmd *cobra.Command, now time.Time, defaultRange time.Duration) (since, until time.Time, err error)
ReadPastTimeRange reads --since and --until like ReadTimeRange, for a range that lies in the past. --until defaults to now and is cut to now when it is in the future, and --since defaults to defaultRange before --until. It returns an error when --since is not in the past or not before --until.
func ReadTimeRange ¶ added in v0.31.0
func ReadTimeRange(cmd *cobra.Command, now time.Time) (since, until *timestamppb.Timestamp, err error)
ReadTimeRange parses the --since and --until flags of cmd with ParseTimeFlag and ParseUntilFlag. Unset flags yield nil so that the server defaults apply. It returns an error when both are set and --since is not before --until.
Types ¶
type IPChanges ¶ added in v0.10.1
type IPChanges = ListChanges
IPChanges holds the parsed result of --allowed-ip flags.
type LabelChanges ¶ added in v0.10.1
LabelChanges holds the parsed result of --label flags.
func ParseLabels ¶ added in v0.10.1
func ParseLabels(raw []string) (*LabelChanges, error)
ParseLabels parses a slice of raw --label flag values into upserts and removals.
Accepted forms:
- "key=value" -- upsert (empty value is valid: "key=")
- "key-" -- remove the label with that key
Returns an error for malformed entries like "key" (no = and no trailing -), "=value" (empty key), or "" (empty string).
When the same key appears multiple times, the last occurrence wins.
type ListChanges ¶ added in v0.30.0
ListChanges holds the parsed result of a string-list flag that supports additions and removals (e.g. --allowed-ip, --allowed-origin).
func ParseListChanges ¶ added in v0.30.0
func ParseListChanges(flag, item string, raw []string) (*ListChanges, error)
ParseListChanges parses a slice of raw flag values into additions and removals. A value with a trailing '-' marks the entry for removal; any other value is added. flag and item are only used in error messages (e.g. "--allowed-origin", "origin").
When the same entry appears multiple times, the last occurrence wins.