Documentation
¶
Index ¶
- Constants
- func ControllerFromCmd(cmd *cobra.Command) (*controller.Exec, error)
- func ExplicitFlag(cmd *cobra.Command, flagName, viperKey string) string
- func LoggerFromCmd(cmd *cobra.Command) (*slog.Logger, error)
- func PrintJSON(cmd *cobra.Command, doc any) error
- func PrintTable(cmd *cobra.Command, headers []string, rows [][]string)
- func PrintYAML(cmd *cobra.Command, doc any) error
- func RegisterLabelSelectorFlag(cmd *cobra.Command)
- func RenderAge(t time.Time, now time.Time) string
- type LabelSelector
- type OutputFormat
Constants ¶
const LabelSelectorFlagName = "selector"
LabelSelectorFlagName is the canonical long flag name for the `-l`/`--selector` label query flag wired onto every `kuke get <kind>` subcommand that supports label filtering.
Variables ¶
This section is empty.
Functions ¶
func ControllerFromCmd ¶
func ControllerFromCmd(cmd *cobra.Command) (*controller.Exec, error)
ControllerFromCmd reuses the controller helper from create/shared.
func ExplicitFlag ¶ added in v0.2.0
ExplicitFlag returns the flag's value only when the user explicitly provided it. This avoids viper.SetDefault side-effects leaking hardcoded defaults (e.g. "default") into list-operation filters, where an unset flag must mean "no filter".
func LoggerFromCmd ¶
LoggerFromCmd reuses the logger helper from create/shared.
func PrintJSON ¶
PrintJSON prints the resource as JSON to cmd.OutOrStdout() so callers can capture output via cobra's cmd.SetOut(buf) in tests.
func PrintTable ¶
PrintTable prints resources in a table format.
func PrintYAML ¶
PrintYAML prints the resource as YAML to cmd.OutOrStdout() so callers can capture output via cobra's cmd.SetOut(buf) in tests. Matches the shape PrintTable already takes.
func RegisterLabelSelectorFlag ¶ added in v0.6.0
RegisterLabelSelectorFlag adds the standard `-l`/`--selector` flag to cmd. Keeping the registration in one place ensures every `kuke get <kind>` verb advertises the same long-name, short-name, and help text.
func RenderAge ¶ added in v0.6.0
RenderAge formats a CreatedAt timestamp as a kubectl-style coarse duration ("5d", "2h", "30s") for the AGE column shared across every `kuke get <kind>` table. The zero time renders as "-" so the column stays width-aligned for resources that have not recorded a creation timestamp yet. Granularity drops a unit at each step (>=1d shows days only, >=1h shows hours only, etc.); sub-second values render as "0s". `now` is injected so tests can pin the reference time.
Types ¶
type LabelSelector ¶ added in v0.6.0
type LabelSelector struct {
// contains filtered or unexported fields
}
LabelSelector is a parsed kubectl-style label selector. The zero value (nil receiver or no requirements) matches every label set, including nil maps.
func ParseLabelSelector ¶ added in v0.6.0
func ParseLabelSelector(s string) (*LabelSelector, error)
ParseLabelSelector parses a kubectl-style label selector string into a LabelSelector. Supported operators per clause:
- `key=value` — label `key` equals `value`
- `key==value` — kubectl alias for `=`
- `key!=value` — label `key` not equal to `value` (or absent)
- `key` — label `key` exists (any value)
- `!key` — label `key` does not exist
Clauses are comma-separated and logically ANDed. Whitespace around commas and operands is trimmed. The empty string parses to a selector that matches every label set.
Set-based operators (`in`, `notin`) are explicitly out of scope per issue #614 — feed them in as a follow-up if needed.
func ParseLabelSelectorFlag ¶ added in v0.6.0
func ParseLabelSelectorFlag(cmd *cobra.Command) (*LabelSelector, error)
ParseLabelSelectorFlag reads the `-l`/`--selector` flag from cmd and returns the parsed selector. An unset or blank flag yields a non-nil empty selector (matches every label set) so callers can pass it through Matches unconditionally. Malformed selectors return a parse error before any controller call — see the issue AC's "fail fast" requirement.
func (*LabelSelector) Empty ¶ added in v0.6.0
func (s *LabelSelector) Empty() bool
Empty reports whether the selector carries zero requirements — i.e. it matches every label set. Useful for "did the user actually pass a selector" gates without inspecting the raw flag value.
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the output format type.
const ( OutputFormatYAML OutputFormat = "yaml" OutputFormatJSON OutputFormat = "json" OutputFormatTable OutputFormat = "table" OutputFormatWide OutputFormat = "wide" )
func ParseOutputFormat ¶
func ParseOutputFormat(cmd *cobra.Command) (OutputFormat, error)
ParseOutputFormat resolves the output format using kuke's standard precedence: explicit `--output`/`-o` flag > KUKE_GET_OUTPUT env (and any other source viper has bound to `kuke/get/output`) > table default. Each `kuke get <kind>` subcommand binds its own `--output` flag to the shared viper key at construction time, but viper only retains the last binding for a given key; reading the active command's flag directly keeps the flag working for every subcommand and lets viper handle the env/config fall-throughs.