Documentation
¶
Index ¶
- Variables
- func AmIRoot() bool
- func CreateDirectory(path string) error
- func CreateWritableDirectory(path string) bool
- func DirectoryExist(path string) bool
- func DirectoryWritable(path string) bool
- func ErrorAndHelp(cfg *ConfigCmd, err string)
- func ExpandPath(rootPath, path interface{}) interface{}
- func FileExist(path string) bool
- func GetHomeDirectory() string
- func GetOffset() int
- func GetUniqueInterface() (string, error)
- func GetWorkingDir() string
- func InitConfig(c *ConfigCmd)
- func Key(cmd *cobra.Command, name string, valType ConfigType, short string, ...) error
- func Run(sub *ConfigCmd, runf func(cfg *ConfigCmd, args []string)) func(*cobra.Command, []string)
- func SetLogFile(appName string)
- type ConfigCmd
- func (c *ConfigCmd) AddConfig(sub *ConfigCmd)
- func (c ConfigCmd) CallSubRun(subName string)
- func (c *ConfigCmd) Execute()
- func (c *ConfigCmd) GKey(name string, valType ConfigType, short string, usage string) error
- func (c *ConfigCmd) GetAppName() string
- func (c *ConfigCmd) GetComputedValue() map[string]func() interface{}
- func (c *ConfigCmd) GetInstanceName() string
- func (c *ConfigCmd) Initialize()
- func (c *ConfigCmd) LKey(name string, valType ConfigType, short string, usage string) error
- func (c *ConfigCmd) SetCheck(name string, isValid func(interface{}) bool)
- func (c *ConfigCmd) SetComputedValue(name string, fval func() interface{})
- func (c *ConfigCmd) SetConstraint(msg string, constraint func() bool)
- func (c *ConfigCmd) SetDefault(name string, value interface{})
- func (c *ConfigCmd) SetNbArgs(nb int)
- func (c *ConfigCmd) SetNormalize(name string, normalize func(interface{}) interface{})
- func (c *ConfigCmd) SetRequired(name string)
- func (c *ConfigCmd) ValidOK() bool
- type ConfigType
Constants ¶
This section is empty.
Variables ¶
var CheckNotEmpty = func(val interface{}) bool { strVal, ok := val.(string) ret := ok && strVal != "" if !ret { fmt.Printf("Error: empty value is not allowed") } return ret }
CheckNotEmpty is a helper function to check a string value is not empty
var CheckTCPHighPort = func(val interface{}) bool { intVal, ok := val.(int) if ok { return intVal >= 1024 && intVal <= 65535 } fmt.Printf("Error: value (%d) is not a TCP high port (between 1024 and 65535) \n", intVal) return false }
CheckTCPHighPort is a helper function to verify a port is tcp high port
var TrimToLower = func(val interface{}) interface{} { strVal, ok := val.(string) if ok { return strings.ToLower(strings.TrimSpace(strVal)) } return val }
TrimToLower is a helper function to normalize value
Functions ¶
func CreateDirectory ¶
func CreateWritableDirectory ¶
func DirectoryExist ¶
func DirectoryWritable ¶
func ExpandPath ¶
func ExpandPath(rootPath, path interface{}) interface{}
func GetHomeDirectory ¶
func GetHomeDirectory() string
func GetUniqueInterface ¶
func Key ¶
func Key(cmd *cobra.Command, name string, valType ConfigType, short string, usage string, global bool) error
Key defines a flag in cobra bound to env and files
func SetLogFile ¶
func SetLogFile(appName string)
SetLogFile set the file to use for application logging (use working directory if the directory defined in the configuration can not be read nor created)
Types ¶
type ConfigCmd ¶
type ConfigCmd struct {
// contains filtered or unexported fields
}
ConfigCmd allows configuration
func NewConfigCmd ¶
func NewConfigCmd(use string, shortDesc string, longDesc string, runf func(cfg *ConfigCmd, args []string)) *ConfigCmd
NewConfigCmd is the constructor for Config
func (*ConfigCmd) Execute ¶
func (c *ConfigCmd) Execute()
Execute Configuration (call it only for root command)
func (*ConfigCmd) GetComputedValue ¶
GetComputedValue sets a value dynamically as the default for a key
func (*ConfigCmd) Initialize ¶
func (c *ConfigCmd) Initialize()
Initialize handle initial configuration
func (*ConfigCmd) SetComputedValue ¶
SetComputedValue sets a value dynamically as the default for a key
func (*ConfigCmd) SetConstraint ¶
SetConstraint sets a constraint
func (*ConfigCmd) SetDefault ¶
SetDefault : set default value for a key
func (*ConfigCmd) SetNormalize ¶
SetNormalize : function to normalize the value of a config Key (if set)
func (*ConfigCmd) SetRequired ¶
SetRequired sets a key as required
type ConfigType ¶
type ConfigType int
ConfigType type used in key definitions
const ( IsStr ConfigType IsInt IsBool )