util

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT, Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDir

func EnsureDir(fileName string)

EnsureDir checks a file could be written to a path, creates the directories as needed

func FileExists

func FileExists(filePath string) bool

FileExists reports whether the named file or directory exists.

func Join

func Join(path, filename string) string

Join joins together a path and filename

func MinUint32

func MinUint32(a, b uint32) uint32

MinUint32 is a helper function to return the minimum of two uint32s. This avoids a math import and the need to cast to floats.

Types

type App

type App struct {
	*cli.App
	// contains filtered or unexported fields
}

func NewApp

func NewApp(name, version, description, copyright string,
	action, before, after func(c *cli.Context) (err error),
) (a *App)

NewApp returns a new App note that this by default includes a datadir for saving the flags defined for the app and a version subcommand (in addition to the flags)

func (*App) AddCommands

func (a *App) AddCommands(c ...cli.Command)

AddCommands appends a slice of cli.Command into an App's commands

func (*App) AddDefaults

func (a *App) AddDefaults(d []cli.Flag, c []ConfByCategories)

AddDefaults appends a set of flags and preset configurations to the existing this is usually what the consuming app will use This should be run after Initialize

func (*App) AddFlags

func (a *App) AddFlags(f ...cli.Flag)

AddFlags appends flags to existing flags

func (*App) AddHook

func (a *App) AddHook(group, name string, fn HookFunc)

AddHook adds a function to react when a configuration Value is changed

func (*App) AddToAfter

func (a *App) AddToAfter(before bool, fn func(c *cli.Context) (err error))

func (*App) Bool

func (a *App) Bool(group, name, usage, envVar string,
	sanitizer ...HookFunc) *cli.BoolFlag

Bool returns an cli.BoolFlag

func (*App) BoolTrue

func (a *App) BoolTrue(group, name, usage, envVar string,
	sanitizer ...HookFunc) *cli.BoolTFlag

BoolTrue returns a CliBoolFlag that defaults to true

func (*App) Duration

func (a *App) Duration(group, name, usage string, value time.Duration, envVar string,
	sanitizer ...HookFunc) *cli.DurationFlag

Duration returns an cli.DurationFlag

func (*App) FlagExists

func (a *App) FlagExists(group, name string) (ok bool)

FlagExists returns true if the configuration item exists

func (*App) Float64

func (a *App) Float64(group, name, usage string, value float64, envVar string,
	sanitizer ...HookFunc) *cli.Float64Flag

Float64 returns an cli.Float64Flag

func (*App) GetBool

func (a *App) GetBool(group, name string) (o bool, err error)

GetBool returns the pointer to the bool of the config item Value

func (*App) GetConf

func (a *App) GetConf(group, name string) (o interface{}, err error)

GetConf returns the interface containing a configuration item at a given path

func (*App) GetDuration

func (a *App) GetDuration(group, name string) (o time.Duration, err error)

GetDuration returns the pointer to the time.Duration of the config item Value

func (*App) GetFloat64

func (a *App) GetFloat64(group, name string) (o float64, err error)

GetFloat64 returns the pointer to the float64 of the config item Value

func (*App) GetInt

func (a *App) GetInt(group, name string) (o int, err error)

GetInt returns the pointer to the int of the config item Value

func (*App) GetString

func (a *App) GetString(group, name string) (o string, err error)

GetString returns the pointer to the string of the config item Value

func (*App) GetStringSlice

func (a *App) GetStringSlice(group, name string) (o cli.StringSlice,
	err error)

GetStringSlice returns the pointer to the string slice of the config item Value

func (*App) GetUint

func (a *App) GetUint(group, name string) (o uint, err error)

GetUint returns the pointer to the uint of the config item Value

func (*App) GroupExists

func (a *App) GroupExists(group string) (ok bool)

GroupExists returns true if the configuration group exists

func (*App) Initialize

func (a *App) Initialize()

Initialize values that can only be generated after the generators run

func (*App) Int

func (a *App) Int(group, name, usage string, value int, envVar string,
	sanitizer ...HookFunc) *cli.IntFlag

Int returns an cli.IntFlag

func (*App) LoadConf

func (a *App) LoadConf() (err error)

LoadConf reads the configuration located in the datadir folder into the app config database

func (*App) NewCommand

func (a *App) NewCommand(name string, usage string, action interface{},
	subcommands cli.Commands, flags []cli.Flag, aliases ...string) cli.Command

NewCommand returns a cli.Command

func (*App) RemoveHook

func (a *App) RemoveHook(group, name string, fn HookFunc)

RemoveHook removes a change hook from a flag

func (*App) SaveConf

func (a *App) SaveConf()

SaveConf writes the configuration data to disk in json format

func (*App) SetBool

func (a *App) SetBool(group, name string, value bool) (err error)

SetBool sets the Value stored in the config item

func (*App) SetCommands

func (a *App) SetCommands(c ...cli.Command)

SetCommands places a slice of cli.Command into an App

func (*App) SetConf

func (a *App) SetConf(group, name string, value interface{}) (err error)

SetConf changes a flag Value and runs any hooks attached to it

func (*App) SetDefaults

func (a *App) SetDefaults(d []cli.Flag, c []ConfByCategories)

SetDefaults loads a set of flag and configured structures into the app this is used to completely reset the defaults This should be run after Initialize

func (*App) SetDuration

func (a *App) SetDuration(group, name string, value time.Duration) (err error)

SetDuration sets the Value stored in the config item

func (*App) SetFlags

func (a *App) SetFlags(f ...cli.Flag)

SetFlags copies in the flags

func (*App) SetFloat64

func (a *App) SetFloat64(group, name string, value float64) (err error)

SetFloat64 sets the Value stored in the config item

func (*App) SetInt

func (a *App) SetInt(group, name string, value int) (err error)

SetInt sets the Value stored in the config item

func (*App) SetString

func (a *App) SetString(group, name, value string) (err error)

SetString sets the Value stored in the config item

func (*App) SetStringSlice

func (a *App) SetStringSlice(group, name string, value []string) (err error)

SetStringSlice sets the Value stored in the config item

func (*App) SetUint

func (a *App) SetUint(group, name string, value uint) (err error)

SetUint sets the Value stored in the config item

func (*App) String

func (a *App) String(group, name, usage, value, envVar string,
	sanitizer ...HookFunc) *cli.StringFlag

String returns an cli.StringFlag

func (*App) StringSlice

func (a *App) StringSlice(group, name, usage string, val []string, envVar string,
	sanitizer ...HookFunc) *cli.StringSliceFlag

StringSlice returns and cli.StringSliceFlag

func (*App) SubCommands

func (a *App) SubCommands(sc ...cli.Command) []cli.Command

SubCommands returns a slice of cli.Command

func (*App) Uint

func (a *App) Uint(group, name, usage string, value uint, envVar string,
	sanitizer ...HookFunc) *cli.UintFlag

Uint returns an cli.UintFlag

type ConfByCategories

type ConfByCategories map[string]ConfCategory

type ConfCategory

type ConfCategory map[string]confItem

type HookFunc

type HookFunc *func(interface{}) error

func CheckPath

func CheckPath() HookFunc

CheckPath cleans the filesystem path of special characters

func CheckURL

func CheckURL() HookFunc

CheckURL cleans the URL

func DurationBounds

func DurationBounds(min, max time.Duration) HookFunc

DurationBounds allows setting a floor and ceiling on a value

func Example

func Example() HookFunc

Example is a dummy that returns always no error, use as a prototype

func Float64Bounds

func Float64Bounds(min, max float64) HookFunc

Float64Bounds allows setting a floor and ceiling on a value

func IntBounds

func IntBounds(min, max int) HookFunc

IntBounds allows setting a floor and ceiling on a value

func ToHookFunc

func ToHookFunc(fn func(interface{}) error) HookFunc

func UintBounds

func UintBounds(min, max uint) HookFunc

UintBounds allows setting a floor and ceiling on a value

Jump to

Keyboard shortcuts

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