config

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 13 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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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.

Types

type Config

type Config struct {

	// TODO: remove this after refactored
	Service     internal.Wrapper
	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) 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) 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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

func (s OptionalBoolean) IsSet() bool

IsSet returns true if OptionalBoolean has been set

func (OptionalBoolean) OverrideNotSet added in v1.0.0

func (s OptionalBoolean) OverrideNotSet(b bool) OptionalBoolean

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

func (*OptionalBoolean) Set added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

func (s OptionalBoolean) String() string

String implements flag.Value

func (OptionalBoolean) Type added in v1.0.0

func (s OptionalBoolean) Type() string

Type implements pflag.Value

func (OptionalBoolean) Value added in v1.0.0

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