Documentation ¶
Overview ¶
Package cmd_config contains helper functions to support constructing Cobra commands, validating arguments and populating Viper config management
Index ¶
- Variables
- func DisplayConfig()
- func SetDefaultFromEnv(k string, configVar string, varType EnvVarType)
- func SetDefaultsFromConfig(configMap map[string]interface{})
- func ValidateSnapshotArgs(ctx context.Context) error
- func Viper() *viper.Viper
- type CmdBuilder
- func (c *CmdBuilder) AddBoolFlag(name string, defaultValue bool, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddCloudFlags() *CmdBuilder
- func (c *CmdBuilder) AddIntFlag(name string, defaultValue int, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddModLocationFlag() *CmdBuilder
- func (c *CmdBuilder) AddStringArrayFlag(name string, defaultValue []string, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddStringFlag(name string, defaultValue string, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddStringMapStringFlag(name string, defaultValue map[string]string, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddStringSliceFlag(name string, defaultValue []string, desc string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddVarFlag(value pflag.Value, name string, usage string, opts ...FlagOption) *CmdBuilder
- func (c *CmdBuilder) AddWorkspaceDatabaseFlag() *CmdBuilder
- type EnvVarType
- type FlagOption
Constants ¶
This section is empty.
Variables ¶
var FlagOptions = struct { Required func() FlagOption Hidden func() FlagOption Deprecated func(string) FlagOption NoOptDefVal func(string) FlagOption WithShortHand func(string) FlagOption }{ Required: requiredOpt, Hidden: hiddenOpt, Deprecated: deprecatedOpt, NoOptDefVal: noOptDefValOpt, WithShortHand: withShortHand, }
FlagOptions - shortcut for common flag options
Functions ¶
func DisplayConfig ¶ added in v0.17.0
func DisplayConfig()
DisplayConfig prints all config set via WorkspaceProfile or HCL options
func SetDefaultFromEnv ¶ added in v0.17.0
func SetDefaultFromEnv(k string, configVar string, varType EnvVarType)
func SetDefaultsFromConfig ¶ added in v0.17.0
func SetDefaultsFromConfig(configMap map[string]interface{})
SetDefaultsFromConfig overrides viper default values from hcl config values
func ValidateSnapshotArgs ¶ added in v0.17.0
Types ¶
type CmdBuilder ¶
type CmdBuilder struct {
// contains filtered or unexported fields
}
func OnCmd ¶
func OnCmd(cmd *cobra.Command) *CmdBuilder
OnCmd starts a config builder wrapping over the provided *cobra.Command
func (*CmdBuilder) AddBoolFlag ¶
func (c *CmdBuilder) AddBoolFlag(name string, defaultValue bool, desc string, opts ...FlagOption) *CmdBuilder
AddBoolFlag ia s helper function to add a boolean flag to a command
func (*CmdBuilder) AddCloudFlags ¶ added in v0.21.0
func (c *CmdBuilder) AddCloudFlags() *CmdBuilder
AddCloudFlags is helper function to add the cloud flags to a command
func (*CmdBuilder) AddIntFlag ¶
func (c *CmdBuilder) AddIntFlag(name string, defaultValue int, desc string, opts ...FlagOption) *CmdBuilder
AddIntFlag is a helper function to add an integer flag to a command
func (*CmdBuilder) AddModLocationFlag ¶ added in v0.21.0
func (c *CmdBuilder) AddModLocationFlag() *CmdBuilder
AddModLocationFlag is helper function to add the mod-location flag to a command
func (*CmdBuilder) AddStringArrayFlag ¶
func (c *CmdBuilder) AddStringArrayFlag(name string, defaultValue []string, desc string, opts ...FlagOption) *CmdBuilder
AddStringArrayFlag is a helper function to add a flag that accepts an array of strings
func (*CmdBuilder) AddStringFlag ¶
func (c *CmdBuilder) AddStringFlag(name string, defaultValue string, desc string, opts ...FlagOption) *CmdBuilder
AddStringFlag is a helper function to add a string flag to a command
func (*CmdBuilder) AddStringMapStringFlag ¶
func (c *CmdBuilder) AddStringMapStringFlag(name string, defaultValue map[string]string, desc string, opts ...FlagOption) *CmdBuilder
AddStringMapStringFlag is a helper function to add a flag that accepts a map of strings
func (*CmdBuilder) AddStringSliceFlag ¶
func (c *CmdBuilder) AddStringSliceFlag(name string, defaultValue []string, desc string, opts ...FlagOption) *CmdBuilder
AddStringSliceFlag is a helper function to add a flag that accepts an array of strings
func (*CmdBuilder) AddVarFlag ¶ added in v0.23.0
func (c *CmdBuilder) AddVarFlag(value pflag.Value, name string, usage string, opts ...FlagOption) *CmdBuilder
func (*CmdBuilder) AddWorkspaceDatabaseFlag ¶ added in v0.21.0
func (c *CmdBuilder) AddWorkspaceDatabaseFlag() *CmdBuilder
AddWorkspaceDatabaseFlag is helper function to add the workspace-databse flag to a command
type EnvVarType ¶ added in v0.20.0
type EnvVarType int
const ( String EnvVarType = iota Int Bool )
func (EnvVarType) String ¶ added in v0.20.0
func (i EnvVarType) String() string