cli

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NameArgumentName  = "name"
	NamesArgumentName = "name(s)"
)
View Source
const (
	AllNamespacesFlagName = "--all-namespaces"
	ContextFlagName       = "--context"
	KubeConfigFlagName    = "--kubeconfig"
	NamespaceFlagName     = "--namespace"
	NoColorFlagName       = "--no-color"
)

Variables

View Source
var ErrIgnoreArg = fmt.Errorf("ignore argument")
View Source
var SilentError = &silentError{}

Functions

func AllNamespacesFlag

func AllNamespacesFlag(ctx context.Context, cmd *cobra.Command, c *Config, namespace *string, allNamespaces *bool)

func Args

func Args(cmd *cobra.Command, argDefs ...Arg)

func CommandFromContext

func CommandFromContext(ctx context.Context) *cobra.Command

func DryRunResource

func DryRunResource(ctx context.Context, resource runtime.Object, gvk schema.GroupVersionKind)

func ExecE

func ExecE(ctx context.Context, c *Config, obj Executable) func(cmd *cobra.Command, args []string) error

ExecE bridges a cobra RunE function to the Executable interface. All flags and arguments must already be bound, with explicit or default values, to the struct being executed. This function is typically used to define the RunE phase of a command.

```

cmd := &cobra.Command{
	   ...
	   RunE: cli.ExecE(c, obj),
}

```

func FormatArgs

func FormatArgs(cmd *cobra.Command) string

func NamespaceFlag

func NamespaceFlag(ctx context.Context, cmd *cobra.Command, c *Config, namespace *string)

func NewCacheDiscoveryClient added in v0.9.0

func NewCacheDiscoveryClient(discoveryClient *discovery.DiscoveryClient) *cachedDiscoveryClient

func NewConfirmSurvey added in v0.10.0

func NewConfirmSurvey(c *Config, format string, a ...any) *interact.Interaction

NewConfirmSurvey create a survey asking for [yN] confirmation when `Resolve` is called

func PrintPrompt added in v0.11.0

func PrintPrompt(shouldPrint bool, printer func(string, ...interface{}) (int, error), format string, a ...interface{})

func PrintPromptWithEmoji added in v0.11.0

func PrintPromptWithEmoji(shouldPrint bool, printer func(Icon, string, ...interface{}) (int, error), icon Icon, format string, a ...interface{})

func ReadStdin

func ReadStdin(c *Config, value *[]byte, prompt string) func(*cobra.Command, []string) error

func Sequence

func Sequence(items ...func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string) error

func SilenceError

func SilenceError(err error) error

func StdoutFromContext

func StdoutFromContext(ctx context.Context) io.Writer

func StripDash

func StripDash(flagName string) string

func ValidateE

func ValidateE(ctx context.Context, obj validation.Validatable) func(cmd *cobra.Command, args []string) error

ValidateE bridges a cobra RunE function to the Validatable interface. All flags and arguments must already be bound, with explicit or default values, to the struct being validated. This function is typically used to define the PreRunE phase of a command.

```

cmd := &cobra.Command{
	   ...
	   PreRunE: cli.ValidateE(obj),
}

```

func Visit

func Visit(cmd *cobra.Command, f func(c *cobra.Command) error) error

func WithCommand

func WithCommand(ctx context.Context, cmd *cobra.Command) context.Context

func WithStdout

func WithStdout(ctx context.Context, stdout io.Writer) context.Context

Types

type Arg

type Arg struct {
	Name     string
	Arity    int
	Optional bool
	Set      func(cmd *cobra.Command, args []string, offset int) error
}

func BareDoubleDashArgs

func BareDoubleDashArgs(values *[]string) Arg

func NameArg

func NameArg(name *string) Arg

func NamesArg

func NamesArg(names *[]string) Arg

func OptionalNameArg

func OptionalNameArg(name *string) Arg

type Client

type Client interface {
	DefaultNamespace() string
	KubeRestConfig() *rest.Config
	Discovery() discovery.DiscoveryInterface
	SetLogger(logger logr.Logger)
	ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
	ToRESTConfig() (*rest.Config, error)
	ToRESTMapper() (meta.RESTMapper, error)
	crclient.Client
}

func NewClient

func NewClient(kubeConfigFile string, currentContext string, scheme *runtime.Scheme) Client

type Config

type Config struct {
	Name string
	Client
	Scheme          *runtime.Scheme
	ViperConfigFile string
	KubeConfigFile  string
	CurrentContext  string
	TanzuIgnoreFile string
	Exec            func(ctx context.Context, command string, args ...string) *exec.Cmd
	Stdin           io.Reader
	Stdout          io.Writer
	Stderr          io.Writer
	Verbose         *int32
	Builder         *resource.Builder
	NoColor         bool
}

func Initialize

func Initialize(name string, scheme *runtime.Scheme) *Config

func NewDefaultConfig

func NewDefaultConfig(name string, scheme *runtime.Scheme) *Config

func (*Config) Boldf added in v0.7.0

func (c *Config) Boldf(format string, a ...interface{}) (n int, err error)

func (*Config) Eboldf added in v0.7.0

func (c *Config) Eboldf(format string, a ...interface{}) (n int, err error)

func (*Config) Eerrorf

func (c *Config) Eerrorf(format string, a ...interface{}) (n int, err error)

func (*Config) Efaintf

func (c *Config) Efaintf(format string, a ...interface{}) (n int, err error)

func (*Config) Einfof

func (c *Config) Einfof(format string, a ...interface{}) (n int, err error)

func (*Config) Emoji added in v0.10.0

func (c *Config) Emoji(emoji Icon, format string, a ...interface{}) (n int, err error)

func (*Config) Eprintf

func (c *Config) Eprintf(format string, a ...interface{}) (n int, err error)

func (*Config) Errorf

func (c *Config) Errorf(format string, a ...interface{}) (n int, err error)

func (*Config) Esuccessf

func (c *Config) Esuccessf(format string, a ...interface{}) (n int, err error)

func (*Config) Faintf

func (c *Config) Faintf(format string, a ...interface{}) (n int, err error)

func (*Config) Infof

func (c *Config) Infof(format string, a ...interface{}) (n int, err error)

func (*Config) Printf

func (c *Config) Printf(format string, a ...interface{}) (n int, err error)

func (*Config) Successf

func (c *Config) Successf(format string, a ...interface{}) (n int, err error)

type DryRunable

type DryRunable interface {
	IsDryRun() bool
}

type Executable

type Executable interface {
	Exec(ctx context.Context, c *Config) error
}

type Icon added in v0.9.0

type Icon rune
const (
	FloppyDisk      Icon = '💾'
	Package         Icon = '📦'
	Delivery        Icon = '🚚'
	SpeechBalloon   Icon = '💬'
	Magnifying      Icon = '🔎'
	Repeat          Icon = '🔁'
	Antenna         Icon = '📡'
	Ship            Icon = '🚢'
	Envelop         Icon = '✉'
	IncomingEnvelop Icon = '📨'
	Canoe           Icon = '🛶'
	Inbox           Icon = '📥'
	Question        Icon = '❓'
	ThumbsUp        Icon = '👍'
	Exclamation     Icon = '❗'
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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