cmdutil

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cmdutil provides shared CLI utilities, including the Factory dependency container.

Index

Constants

View Source
const DNS1123SubdomainMaxLength = 253
View Source
const DefaultHTTPTimeout = 45 * time.Second

DefaultHTTPTimeout caps every portal REST request. Must exceed the portal's own 30s request timeout so its 408 or truncated:true response arrives before the client aborts as a transport error.

View Source
const K8sNamePattern = `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`

K8sNamePattern is the portal's tektonInputSchemas.k8sName shape: lowercase alphanumerics and '-', no dots, start/end alphanumeric. Length is bounded separately by DNS1123SubdomainMaxLength.

View Source
const LoginHint = "Or run: krci auth login --portal-url <url>"

LoginHint suggests running "krci auth login" to configure the CLI.

Variables

View Source
var ClusterNameOption = ConfigOption{
	EnvVar:    "KRCI_CLUSTER_NAME",
	ConfigKey: "cluster-name in ~/.config/krci/config.yaml",
}

ClusterNameOption describes how to set the cluster name.

View Source
var IssuerURLOption = ConfigOption{
	EnvVar:    "KRCI_ISSUER_URL",
	ConfigKey: "issuer-url in ~/.config/krci/config.yaml",
}

IssuerURLOption describes how to set the OIDC issuer URL.

View Source
var NamespaceOption = ConfigOption{
	EnvVar:    "KRCI_NAMESPACE",
	ConfigKey: "namespace in ~/.config/krci/config.yaml",
}

NamespaceOption describes how to set the namespace.

View Source
var PortalURLOption = ConfigOption{
	Flag:      "--portal-url",
	EnvVar:    "KRCI_PORTAL_URL",
	ConfigKey: "portal-url in ~/.config/krci/config.yaml",
}

PortalURLOption describes how to set the portal URL.

Functions

func ConfigNotSetError added in v0.3.0

func ConfigNotSetError(fieldName, prefix string, opts ConfigOption, hint string) error

ConfigNotSetError returns a formatted error for a missing configuration field. When prefix is empty, the error opens with "<fieldName> not configured". When prefix is non-empty, it is used verbatim as the opening line. hint, when non-empty, is appended after the options list.

func ErrAuthRequired added in v0.3.0

func ErrAuthRequired(cause error) error

ErrAuthRequired wraps a cause into a user-facing "authentication required" error with a hint to run "krci auth login".

func ExactArgs added in v0.4.0

func ExactArgs(n int, usage string, hint ...string) cobra.PositionalArgs

ExactArgs returns a cobra.PositionalArgs that requires exactly n arguments, producing a user-friendly error message that names the missing argument. An optional hint is appended as a "Hint:" line when provided.

func GuardFlagValues added in v0.18.0

func GuardFlagValues(root *cobra.Command)

GuardFlagValues prepends validateStringFlags to the Args check of every runnable leaf command under root; a leaf without Args gets cobra.ArbitraryArgs. Group commands keep their nil Args and cobra's unknown-command check. Call once, after every AddCommand and after InitDefaultHelpCmd and InitDefaultCompletionCmd on the root; cobra otherwise adds those two commands inside Execute, unwrapped.

func IsValidDNS1123Label added in v0.8.0

func IsValidDNS1123Label(s string) bool

func ValidateK8sName added in v0.15.0

func ValidateK8sName(placeholder, value string) error

ValidateK8sName is the single validator for a Kubernetes resource name the user types: project, pipeline, deployment, env, cluster. placeholder names the argument in the error, e.g. "<project>" or "--cluster".

Types

type ConfigOption added in v0.3.0

type ConfigOption struct {
	Flag      string // e.g. "--portal-url" (empty if not available)
	EnvVar    string // e.g. "KRCI_PORTAL_URL"
	ConfigKey string // e.g. "portal-url in ~/.config/krci/config.yaml"
}

ConfigOption describes one way to set a configuration value.

type Factory

type Factory struct {
	IOStreams     *iostreams.IOStreams
	Config        func() (*config.Config, error)
	TokenProvider func() (auth.TokenProvider, error)
	RestClient    func() (*restapi.ClientWithResponses, error)
}

Factory holds lazy-func dependencies shared across all CLI commands. Each func is memoized: the first call resolves the dependency; subsequent calls return the cached result instantly.

func New

func New() *Factory

New creates a Factory wired to real system resources. Config, TokenProvider, and RestClient are lazily resolved after Cobra parses command-line flags (triggered by PersistentPreRunE on the root command).

Jump to

Keyboard shortcuts

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