cmdutil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

cmdutil package provides some common CLI utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SelectorOptions

type SelectorOptions struct {
	// contains filtered or unexported fields
}

SelectorOptions holds values for selectors/filtering options given on CLI and provides methods to configure a Cobra command instance with necessary flags, as well to transform options into a `ctl.SelectorConfig` suitable for using with ctl methods.

func NewSelectorOptions

func NewSelectorOptions() *SelectorOptions

func (*SelectorOptions) AddFlags

func (so *SelectorOptions) AddFlags(cmd *cobra.Command)

AddFlags adds label and field selector flags to given cobra command. If capturing arguments was also previously enabled with a call to WithCapturingArgsUsingValidator, this will also add hook to the command that captures positional arguments and assigns them as name expressions in the selector.

func (*SelectorOptions) NameExpressions

func (so *SelectorOptions) NameExpressions(names ...string) *SelectorOptions

NameExpressions assigns given names as name expressions to use for filtering objects by name.

func (*SelectorOptions) ToConfig

func (so *SelectorOptions) ToConfig() *ctl.SelectorConfig

ToConfig takes values populated by CLI flags and produces a `SelectorConfig` that can be used with `ctl` app Port methods.

func (*SelectorOptions) WithCapturingArgsUsingValidator

func (so *SelectorOptions) WithCapturingArgsUsingValidator() *SelectorOptions

WithCapturingArgsUsingValidator configures this SelectorOptions (specifically its AddToCommand method) to also add hooks to given cobra Command to capture positional arguments and assign them as name expressions.

It does this by assigning a function to `cmd.Args` that acts as a validator of received parameters, and also captures them and saves in SelectorOptions.

Use this only when the command doesn't use its own positional arguments. If it does you can instead process the received parameters and separate the command's args from name expressions, and call NameExpressions method to assign them before a call to ToConfig.

Jump to

Keyboard shortcuts

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