Documentation
¶
Overview ¶
Package cmd provides one stop shopping for a command line executable to bind the correct flags, build the client config, and create a working client. The code for usage looks like this:
clientBuilder := clientcmd.NewBuilder(clientcmd.NewDefaultAuthLoader()) clientBuilder.BindFlags(cmds.PersistentFlags()) apiClient, err := clientBuilder.Client()
Index ¶
Constants ¶
const (
FlagApiServer = "server"
FlagMatchApiVersion = "match-server-version"
FlagApiVersion = "api-version"
FlagAuthPath = "auth-path"
FlagInsecure = "insecure-skip-tls-verify"
FlagCertFile = "client-certificate"
FlagKeyFile = "client-key"
FlagCAFile = "certificate-authority"
FlagBearerToken = "token"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthLoader ¶
type AuthLoader interface {
// LoadAuth takes a path to a config file and can then do anything it needs in order to return a valid clientauth.Info
LoadAuth(path string) (*clientauth.Info, error)
}
AuthLoaders are used to build clientauth.Info objects.
func NewDefaultAuthLoader ¶
func NewDefaultAuthLoader() AuthLoader
NewDefaultAuthLoader returns a default implementation of an AuthLoader that only reads from a config file
func NewPromptingAuthLoader ¶
func NewPromptingAuthLoader(reader io.Reader) AuthLoader
NewDefaultAuthLoader is an AuthLoader that parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.
type BoolFlag ¶
type BoolFlag struct {
Default bool
Value bool
WasProvided bool
}
BoolFlag implements FlagProvider
func (*BoolFlag) SetDefault ¶
func (flag *BoolFlag) SetDefault(value bool)
SetDefault sets a default value for a flag while keeping Provided() false
type Builder ¶
type Builder interface {
// BindFlags must bind and keep track of all the flags required to build a client config object
BindFlags(flags *pflag.FlagSet)
// Config uses the values of the bound flags and builds a complete client config
Config() (*client.Config, error)
// Client calls BuildConfig under the covers and uses that config to return a client
Client() (*client.Client, error)
}
Builder are used to bind and interpret command line flags to make it easy to get an api server client
func NewBuilder ¶
func NewBuilder(authLoader AuthLoader) Builder
NewBuilder returns a valid Builder that uses the passed authLoader. If authLoader is nil, the NewDefaultAuthLoader is used.
type FlagProvider ¶
type FlagProvider interface {
// Provided returns true iff .Set was called on this flag
Provided() bool
pflag.Value
}
FlagProvider adds a check for whether .Set was called on this flag variable
type StringFlag ¶
type StringFlag struct {
Default string
Value string
WasProvided bool
}
StringFlag implements FlagProvider
func (*StringFlag) SetDefault ¶
func (flag *StringFlag) SetDefault(value string)
SetDefault sets a default value for a flag while keeping Provided() false