Documentation
¶
Index ¶
- Variables
- func AddOutputFlag(fs *pflag.FlagSet, outputVar *OutputFormat, defaultOutput OutputFormat, ...)
- func Fatal(code int, format string, values ...any)
- func FilterSlice[X any](data []X, predicate func(X) bool) []X
- func GetCurrentApiserverHost(kcfg *clientcmdapi.Config) (string, error)
- func IsRequirementError(err error) bool
- func MarshalKubeconfig(kcfg *clientcmdapi.Config) ([]byte, error)
- func NaturalLanguageJoin(data []string, separator string, oxfordComma bool) string
- func ParseKubeconfig(data []byte) (*clientcmdapi.Config, error)
- func ParseKubeconfigFromFile(path string) (*clientcmdapi.Config, error)
- func ParseKubeconfigFromFileWithClient(path string) (*clientcmdapi.Config, client.Client, error)
- func ParseKubeconfigWithClient(data []byte) (*clientcmdapi.Config, client.Client, error)
- func Project[X any, Y any](data []X, project func(X) Y) []Y
- func PromptForConfirmation(prompt string, newline bool) bool
- func StringPadding(s string, l int) string
- func UnknownOutputFatal(output OutputFormat)
- func ValidateOutputFormat(output OutputFormat, validOutputs ...OutputFormat)
- type OutputFormat
- type Requirement
- type RequirementError
- type Requirements
- type Table
- type WriteBuffer
Constants ¶
This section is empty.
Variables ¶
var DefaultOutputFormats = []OutputFormat{OUTPUT_JSON, OUTPUT_TEXT, OUTPUT_YAML}
Functions ¶
func AddOutputFlag ¶
func AddOutputFlag(fs *pflag.FlagSet, outputVar *OutputFormat, defaultOutput OutputFormat, validOutputs ...OutputFormat)
AddOutputFlag adds a --output/-o flag to the given FlagSet, binding the result to the given string variable.
func Fatal ¶
Fatal prints the given error message to stderr and then exits with the given exit code.
func FilterSlice ¶
FilterSlice takes a slice and filters it using the given predicate function. Does not modify the original slice, but values are not deep-copied, so changes to the values might influence the original slice, depending on the type.
func GetCurrentApiserverHost ¶
func GetCurrentApiserverHost(kcfg *clientcmdapi.Config) (string, error)
GetCurrentApiserverHost returns the current apiserver host from the given kubeconfig.
func IsRequirementError ¶
func MarshalKubeconfig ¶
func MarshalKubeconfig(kcfg *clientcmdapi.Config) ([]byte, error)
MarshalKubeconfig returns the yaml representation of the given kubeconfig.
func NaturalLanguageJoin ¶
NaturalLanguageJoin works like strings.Join, but it separates the last element via ' and ' instead of comma. For exactly two elements, the result is '<elem> and <elem>'.
func ParseKubeconfig ¶
func ParseKubeconfig(data []byte) (*clientcmdapi.Config, error)
ParseKubeconfig parses the given data as a kubeconfig and returns the parsed config.
func ParseKubeconfigFromFile ¶
func ParseKubeconfigFromFile(path string) (*clientcmdapi.Config, error)
ParseKubeconfigFromFile reads the given file and parses it as kubeconfig.
func ParseKubeconfigFromFileWithClient ¶
ParseKubeconfigFromFileWithClient works like ParseKubeconfigFromFile, but it returns a client.Client in addition to the parsed kubeconfig.
func ParseKubeconfigWithClient ¶
ParseKubeconfigWithClient works like ParseKubeconfig, but it returns a client.Client in addition to the parsed kubeconfig.
func Project ¶
Project takes a list and converts/projects each element of the list to another type using the given project function.
func PromptForConfirmation ¶
PromptForConfirmation prompts the user for confirmation.
func StringPadding ¶
StringPadding returns the given string filled with spaces to the given length. If the string already has the required or a greater length, it is returned unmodified.
func UnknownOutputFatal ¶
func UnknownOutputFatal(output OutputFormat)
UnknownOutputFatal prints an error message that the specified output format is not known and then exits with status 1.
func ValidateOutputFormat ¶
func ValidateOutputFormat(output OutputFormat, validOutputs ...OutputFormat)
ValidateOutputFormat verifies that a valid output format was specified and exits with error otherwise.
Types ¶
type OutputFormat ¶
type OutputFormat string
const ( OUTPUT_TEXT OutputFormat = "text" OUTPUT_YAML OutputFormat = "yaml" OUTPUT_JSON OutputFormat = "json" )
type Requirement ¶
type Requirement struct {
Satisfy func() error
// contains filtered or unexported fields
}
Requirement represents a requirement, consisting of a 'Satisfy' method and a boolean to check whether it has been called.
func (*Requirement) IsSatisfied ¶
func (r *Requirement) IsSatisfied() bool
IsSatisfied returns whether the requirement is satisfied (= its 'Satisfy' method has been called before)
type RequirementError ¶
type RequirementError struct {
// Requirement is the name of the requirement which caused the error
Requirement string
// Error is the error
Err error
}
func NewRequirementError ¶
func NewRequirementError(req string, err error) RequirementError
func (RequirementError) Error ¶
func (re RequirementError) Error() string
type Requirements ¶
type Requirements map[string]*Requirement
Requirements is a helper struct for object methods which require other methods to have been called before.
func NewRequirements ¶
func NewRequirements() Requirements
NewRequirements returns a new Requirements object.
func (Requirements) HasRequirement ¶
func (rs Requirements) HasRequirement(id string) bool
HasRequirement returns whether a requirement with the given ID has been registered.
func (Requirements) IsSatisfied ¶
func (rs Requirements) IsSatisfied(id string) bool
IsSatisfied returns true if a requirement with the given ID has been registered and satisfied.
func (Requirements) Register ¶
func (rs Requirements) Register(id string, satisfy func() error)
Register registers a new requirement. It takes an identifier and a function which, when called, will satisfy the requirement.
func (Requirements) Require ¶
func (rs Requirements) Require(ids ...string) error
Require checks if all referenced requirements have been satisfied. It returns an error if any of the given IDs doesn't match a requirement which has been registered before. For all requirements, it is checked whether the requirement is already satisfied.
If not, its 'Satisfy' method is called. If 'Satisfy' returns without errors, the requirement is marked as satisfied, otherwise the error is returned without checking further requirements.
func (Requirements) SetSatisfied ¶
func (rs Requirements) SetSatisfied(id string, satisfied bool) error
SetSatisfied allows to manually satisfy (or 'unsatisfy') a requirement.
type Table ¶
type Table[T any] struct { // contains filtered or unexported fields }
Table is a helper struct to format output as table.
func NewOutputTable ¶
NewOutputTable returns a new Table for constructing output formatted as a table.
func (*Table[T]) WithColumn ¶
WithColumn adds a new column with the given name and getter function to the table.
type WriteBuffer ¶
type WriteBuffer struct {
// contains filtered or unexported fields
}
func NewWriteBuffer ¶
func NewWriteBuffer() *WriteBuffer
func (*WriteBuffer) Data ¶
func (w *WriteBuffer) Data() []byte
func (*WriteBuffer) Flush ¶
func (w *WriteBuffer) Flush(target io.Writer, replacements ...string) error
Flush writes the buffer to the target writer and resets it. If replacements are provided, all occurrences of the first element in each pair are replaced with the second element. In case of an uneven number of replacements, the last replacement is ignored.
func (*WriteBuffer) FlushToString ¶
func (w *WriteBuffer) FlushToString() string