cmdconfig

package
v0.20.7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: AGPL-3.0 Imports: 20 Imported by: 1

Documentation

Overview

Package cmd_config contains helper functions to support constructing Cobra commands, validating arguments and populating Viper config management

Index

Constants

This section is empty.

Variables

View Source
var FlagOptions = struct {
	Required      func() flagOpt
	Hidden        func() flagOpt
	Deprecated    func(string) flagOpt
	NoOptDefVal   func(string) flagOpt
	WithShortHand func(string) flagOpt
}{
	Required:      requiredOpt,
	Hidden:        hiddenOpt,
	Deprecated:    deprecatedOpt,
	NoOptDefVal:   noOptDefValOpt,
	WithShortHand: withShortHand,
}

FlagOptions :: shortcut for common flag options

Functions

func BootstrapViper

func BootstrapViper(loader *steampipeconfig.WorkspaceProfileLoader, cmd *cobra.Command) error

BootstrapViper sets up viper with the essential path config (workspace-chdir and install-dir)

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 SetDefaultsFromEnv added in v0.19.0

func SetDefaultsFromEnv()

set default values from env vars

func ValidateSnapshotArgs added in v0.17.0

func ValidateSnapshotArgs(ctx context.Context) error

func Viper

func Viper() *viper.Viper

Viper fetches the global viper instance

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 ...flagOpt) *CmdBuilder

AddBoolFlag ia s helper function to add a boolean flag to a command

func (*CmdBuilder) AddIntFlag

func (c *CmdBuilder) AddIntFlag(name string, defaultValue int, desc string, opts ...flagOpt) *CmdBuilder

AddIntFlag is a helper function to add an integer flag to a command

func (*CmdBuilder) AddStringArrayFlag

func (c *CmdBuilder) AddStringArrayFlag(name string, defaultValue []string, desc string, opts ...flagOpt) *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 ...flagOpt) *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 ...flagOpt) *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 ...flagOpt) *CmdBuilder

AddStringSliceFlag is a helper function to add a flag that accepts an array of strings

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

Jump to

Keyboard shortcuts

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