config

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyClientTimeout defines the viper configuration key used to define client timeout
	KeyClientTimeout = "client-timeout"
	// KeyOutput defines the viper configuration key used to define the output
	KeyOutput = "output"
	// ValueOutputHuman defines the viper configuration value used to define human-readable output
	ValueOutputHuman = "human"
	// ValueOutputYAML defines the viper configuration value used to define YAML output
	ValueOutputYAML = "yaml"
	// ValueOutputJSON defines the viper configuration value used to define JSON output
	ValueOutputJSON = "json"
)
View Source
const (
	// FalseFlagValue false Bool String value
	FalseFlagValue = "false"
	// TrueFlagValue true Bool String value
	TrueFlagValue = "true"
)

Variables

View Source
var (
	// Version contains the current version.
	Version = "dev"
	// BuildDate contains a string with the build date.
	BuildDate = "unknown"
)

Functions

func AddEnableDisableFlags

func AddEnableDisableFlags(flags *pflag.FlagSet, target *OptionalBoolean, name, subject string)

AddEnableDisableFlags is a convenience method to generate --enable-something and --disable-something flags with the correct settings.

*name* specifies the name of the flags (eg. '--enable-[name]') *subject* is used to create the usage description for the flags, in the form of 'Enable [subject]'.

func AddEnableOrDisableFlag

func AddEnableOrDisableFlag(flags *pflag.FlagSet, target *OptionalBoolean, defaultValue bool, name, subject string)

AddEnableOrDisableFlag is a convenience method to generate --enable-something *or* --disable-something flag with the correct settings, to overrider the default value. eg. if default is true, flag --disable-something will be generated.

*name* specifies the name of the flag (eg. '--enable-[name]') *subject* is used to create the usage description for the flag, in the form of 'Enable [subject]'.

func AddToggleFlag

func AddToggleFlag(flags *pflag.FlagSet, target *OptionalBoolean, name string, defaultValue bool, usage string)

AddToggleFlag is a convenience method to generate --toggle type of a flag with the correct settings and a default value.

func GetProgressOutputConfig

func GetProgressOutputConfig() *progress.OutputConfig

func GetVersion

func GetVersion() string

Types

type Config

type Config struct {
	GlobalFlags GlobalFlags
	// contains filtered or unexported fields
}

Config holds the configuration for running upctl

func New

func New() *Config

New returns a new instance of Config bound to the given viper instance

func (*Config) BoundFlags

func (s *Config) BoundFlags() []*pflag.Flag

BoundFlags returns the list of all the flags given to the config

func (*Config) Cancel added in v2.5.0

func (s *Config) Cancel()

func (*Config) ClientTimeout

func (s *Config) ClientTimeout() time.Duration

ClientTimeout is a convenience method that returns the user specified client timeout

func (*Config) ConfigBindFlagSet

func (s *Config) ConfigBindFlagSet(flags *pflag.FlagSet)

ConfigBindFlagSet sets the config flag set and binds them to the viper instance

func (*Config) Context added in v2.5.0

func (s *Config) Context() context.Context

func (*Config) CreateService

func (s *Config) CreateService() (internal.AllServices, error)

CreateService creates a new service instance and puts in the conf struct

func (*Config) FlagByKey

func (s *Config) FlagByKey(key string) *pflag.Flag

FlagByKey returns pflag.Flag associated with a key in config

func (*Config) Get

func (s *Config) Get(key string) interface{}

Get return the value of the key in the current namespace

func (*Config) GetString

func (s *Config) GetString(key string) string

GetString is a convenience method of getting a configuration value in the current namespace as a string

func (*Config) IsSet

func (s *Config) IsSet(key string) bool

IsSet return true if the key is set in the current namespace

func (*Config) Load

func (s *Config) Load() error

Load loads config and sets up service

func (*Config) Output

func (s *Config) Output() string

Output is a convenience method for getting the user specified output

func (*Config) OutputHuman

func (s *Config) OutputHuman() bool

OutputHuman is a convenience method that returns true if the user specified human-readable output

func (*Config) Viper

func (s *Config) Viper() *viper.Viper

Viper returns a reference to the viper instance

type GlobalFlags

type GlobalFlags struct {
	ConfigFile    string        `valid:"-"`
	ClientTimeout time.Duration `valid:"-"`
	Debug         bool          `valid:"-"`
	OutputFormat  string        `valid:"in(human|json|yaml)"`
	NoColours     OptionalBoolean
	ForceColours  OptionalBoolean
}

GlobalFlags holds information on the flags shared among all commands

type OptionalBoolean

type OptionalBoolean int

OptionalBoolean represents a boolean that can also be 'not set', eg. having three possible states. OptionalBoolean implements pflag.Value and flag.Value and as such, can be used with flag.Var() and friends. However, it does not allow to be set more than once, in order to support multiple flags touching the same boolean, eg. when the use case is --enable-something'/--disable-something

const (
	// Unset is the OptionalBoolean value representing not set
	Unset OptionalBoolean = iota // 0
	// True is the OptionalBoolean value representing true
	True
	// False is the OptionalBoolean value representing false
	False

	// DefaultTrue is the OptionalBoolean value representing not set, but with a default value of true.
	// It returns false from IsSet, to allow for overriding the default (once)
	DefaultTrue
	// DefaultFalse is the OptionalBoolean value representing not set, but with a default value of false.
	// It returns false from IsSet, to allow for overriding the default (once)
	DefaultFalse
)

func (OptionalBoolean) AsUpcloudBoolean

func (s OptionalBoolean) AsUpcloudBoolean() upcloud.Boolean

AsUpcloudBoolean return OptionalBoolean as upcloud.Boolean nb. DefaultTrue and DefaultEmpty return upcloud.Empty, as upcloud.Boolean has no concept of default values

func (OptionalBoolean) IsSet

func (s OptionalBoolean) IsSet() bool

IsSet returns true if OptionalBoolean has been set

func (OptionalBoolean) OverrideNotSet

func (s OptionalBoolean) OverrideNotSet(b bool) OptionalBoolean

OverrideNotSet returns a OptionalBoolean set to b if the original OptionalBoolean was not set

func (*OptionalBoolean) Set

func (s *OptionalBoolean) Set(value string) error

Set implements flag.Value nb. OptionalBoolean will not allow itself to be set twice, if you want to have an underlying default value, use SetDefault()

func (*OptionalBoolean) SetDefault

func (s *OptionalBoolean) SetDefault(b bool)

SetDefault sets the default value of OptionalBoolean to b Default value is returned from Value() if the OptionalBoolean has not been set

func (OptionalBoolean) String

func (s OptionalBoolean) String() string

String implements flag.Value

func (OptionalBoolean) Type

func (s OptionalBoolean) Type() string

Type implements pflag.Value

func (OptionalBoolean) Value

func (s OptionalBoolean) Value() bool

Value returns the underlying bool for OptionalBoolean. nb. returns false if flag is not set

Jump to

Keyboard shortcuts

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