Documentation
¶
Overview ¶
Package cliutil holds tiny env/flag helpers shared by Wardyn's cmd/* main packages (each cmd is its own `main` package, so these can't just live in one of them without the others importing "main").
Index ¶
- func EnvBool(name string, def bool) bool
- func EnvDuration(name string, def time.Duration) time.Duration
- func EnvOr(key, def string) string
- func FlagBool(name, env string, def bool, usage string) *bool
- func FlagDuration(name, env string, def time.Duration, usage string) *time.Duration
- func FlagEnv(name, env, def, usage string) *string
- func FlagIntEnv(name, env string, def int, usage string) *int
- func SplitCSV(s string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvBool ¶ added in v0.3.1
EnvBool reads a bool directly from an env var, with no flag registered — for sites where flag.Parse() has already run before the read (so FlagBool's flag would never be parsed: a dead flag). Same token set and loudness contract as FlagBool: unset/empty keeps def quietly (correct for `docker run -e VAR`), 1/true/yes/on is true, 0/false/no/off is false, anything else exits 2.
func EnvDuration ¶ added in v0.3.1
EnvDuration reads a time.Duration directly from an env var, with no flag registered — the non-flag twin of FlagDuration for post-flag.Parse() sites. Unset/empty keeps def quietly; an unparseable value exits 2 rather than silently reinstating the default (a typo'd interval must not be reinterpreted).
func FlagBool ¶
FlagBool defines a bool flag whose default is overridden by an env var. 1/true/yes/on is true, 0/false/no/off is false (case-insensitive, trimmed). Unset — or set to the empty string, which is what `docker run -e VAR` and a compose `VAR=` passthrough produce for an unset var — means "use the default", silently. Anything else exits 2: a value that is neither truthy nor falsey states no intent this helper can honor, and guessing "false" is the worst guess available (it turns features off).
func FlagDuration ¶
FlagDuration defines a time.Duration flag whose default is overridden by an env var. Unset/empty keeps the default; an unparseable value exits 2 rather than silently reinstating the default — an operator who typos an interval must not have it quietly reinterpreted as a different, meaningful setting.
func FlagIntEnv ¶
FlagIntEnv defines an int flag whose default is overridden by an env var. Unset/empty keeps the default; an unparseable value exits 2 (see FlagDuration).
Types ¶
This section is empty.