util

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyFlagChanged added in v0.16.0

func AnyFlagChanged(cmd *cobra.Command, flags []string) bool

AnyFlagChanged reports whether any flag in the given list was set by the user.

func ApplyIPs added in v0.10.1

func ApplyIPs(existing []string, changes *IPChanges) []string

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 ConfirmAction

func ConfirmAction(force bool, w io.Writer, prompt string) bool

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 IsUUID added in v0.16.0

func IsUUID(s string) bool

IsUUID returns true if s is a valid UUID.

Types

type IPChanges added in v0.10.1

type IPChanges struct {
	Add    []string
	Remove map[string]bool
}

IPChanges holds the parsed result of --allowed-ip flags.

func ParseIPs added in v0.10.1

func ParseIPs(raw []string) (*IPChanges, error)

ParseIPs parses a slice of raw --allowed-ip flag values into additions and removals.

Accepted forms:

  • "10.0.0.0/8" -- add the IP CIDR
  • "10.0.0.0/8-" -- remove the IP CIDR (trailing dash)

When the same IP appears multiple times, the last occurrence wins.

type LabelChanges added in v0.10.1

type LabelChanges struct {
	Set    map[string]string
	Remove map[string]bool
}

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.

Jump to

Keyboard shortcuts

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