Documentation ¶
Index ¶
- Constants
- Variables
- func AddEnableDisableFlags(flags *pflag.FlagSet, target *OptionalBoolean, name, subject string)
- func AddEnableOrDisableFlag(flags *pflag.FlagSet, target *OptionalBoolean, defaultValue bool, ...)
- func AddToggleFlag(flags *pflag.FlagSet, target *OptionalBoolean, name string, defaultValue bool, ...)
- type Config
- func (s *Config) BoundFlags() []*pflag.Flag
- func (s *Config) ClientTimeout() time.Duration
- func (s *Config) ConfigBindFlagSet(flags *pflag.FlagSet)
- func (s *Config) CreateService() (internal.AllServices, error)
- func (s *Config) FlagByKey(key string) *pflag.Flag
- func (s *Config) Get(key string) interface{}
- func (s *Config) GetString(key string) string
- func (s *Config) IsSet(key string) bool
- func (s *Config) Load() error
- func (s *Config) Output() string
- func (s *Config) OutputHuman() bool
- func (s *Config) Viper() *viper.Viper
- type GlobalFlags
- type OptionalBoolean
- func (s OptionalBoolean) AsUpcloudBoolean() upcloud.Boolean
- func (s OptionalBoolean) IsSet() bool
- func (s OptionalBoolean) OverrideNotSet(b bool) OptionalBoolean
- func (s *OptionalBoolean) Set(value string) error
- func (s *OptionalBoolean) SetDefault(b bool)
- func (s OptionalBoolean) String() string
- func (s OptionalBoolean) Type() string
- func (s OptionalBoolean) Value() bool
Constants ¶
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" )
const ( // FalseFlagValue false Bool String value FalseFlagValue = "false" // TrueFlagValue true Bool String value TrueFlagValue = "true" )
Variables ¶
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 ¶
BoundFlags returns the list of all the flags given to the config
func (*Config) ClientTimeout ¶
ClientTimeout is a convenience method that returns the user specified client timeout
func (*Config) ConfigBindFlagSet ¶
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) GetString ¶
GetString is a convenience method of getting a configuration value in the current namespace as a string
func (*Config) OutputHuman ¶
OutputHuman is a convenience method that returns true if the user specified human-readable output
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