dockerflags

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 7 Imported by: 0

README

dockerflags

Some functions that make commandline flags easier to use with docker (where you typically want them in environment variables. More specifically: Add flag.*Var wrappers that pull from a default value, overridden by an environment variable, overridden by the actual flags.

Documentation

Overview

Package dockerflags provides helper functions useful to handle commandline flags in CLI tools used inside Docker containers.

The functions follow a general pattern: Their first parameter is the same as in corresponding functions from the standard `flag` package. The second parameter is the name of an environment variable used to override the default for that flag, the third parameter is the flag name, corresponding to the second parameter in `flag` package functions, followed by the normal default value and the description. Each function appends a small note to the description before passing it to the `flag` package function, informing the user about the environment variable that can override the default.

Generally, the priority order is (from lowest priority to highest):

  • Default value passed to `dockerflags` function.
  • Value from the environment variable (if set and parseable to the given type).
  • flag value given on commandline.

Additionally, helper function to just lookup and parse environment variables are provided. These log a warning if the environment variable is set but the content can't be parsed to the relevant type. Note that there is no lookup function for strings, as that would just be the same as os.LookupEnv.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrorDuringEnvParsing error

This is set to the last error that occurred while parsing environment variables into defaults, but only if the error is not ErrNotFound.

Functions

func BoolVar

func BoolVar(target *bool, envVar, flagname string, defaultval bool, description string)

BoolVar calls FsBoolVar with the flag.CommandLine flagset.

func DurationVar

func DurationVar(target *time.Duration, envVar, flagname string, defaultval time.Duration, description string)

DurationVar calls FsDurationVar with the flag.CommandLine flagset.

func Float64Var

func Float64Var(target *float64, envVar, flagname string, defaultval float64, description string)

Float64Var calls FsFloat64Var with the flag.CommandLine flagset.

func FsBoolVar

func FsBoolVar(fs *flag.FlagSet, target *bool, envVar, flagname string, defaultval bool, description string)

FsBoolVar sets up a flag.BoolVar that uses the value from the OS environment variable envVar as the default if it is set and parseable as a bool, otherwise with the specified default value.

func FsDurationVar

func FsDurationVar(fs *flag.FlagSet, target *time.Duration, envVar, flagname string, defaultval time.Duration, description string)

FsDurationVar sets up a flag.DurationVar in the given flagset, using the value from the OS environment variable envVar as the default if it is set and parseable as a time.Duration, otherwise with the specified default value.

func FsFloat64Var

func FsFloat64Var(fs *flag.FlagSet, target *float64, envVar, flagname string, defaultval float64, description string)

FsFloat64Var sets up a flag.Float64Var that uses the value from the OS environment variable envVar as the default if it is set and parseable as a float64, otherwise with the specified default value.

func FsInt64Var

func FsInt64Var(fs *flag.FlagSet, target *int64, envVar, flagname string, defaultval int64, description string)

FsInt64Var sets up a flag.Int64Var that uses the value from the OS environment variable envVar as the default if it is set and parseable as an int64, otherwise with the specified default value.

func FsIntVar

func FsIntVar(fs *flag.FlagSet, target *int, envVar, flagname string, defaultval int, description string)

FsIntVar sets up a flag.IntVar that uses the value from the OS environment variable envVar as the default if it is set and parseable as an int, otherwise with the specified default value.

func FsStringVar

func FsStringVar(fs *flag.FlagSet, target *string, envVar, flagname, defaultval, description string)

FsStringVar sets up a flag.StringVar in the given flagset, using the value from the OS environment variable envVar as the default if the variable is set.

func Int64Var

func Int64Var(target *int64, envVar, flagname string, defaultval int64, description string)

Int64Var calls FsInt64Var with the flag.CommandLine flagset.

func IntVar

func IntVar(target *int, envVar, flagname string, defaultval int, description string)

IntVar calls FsIntVar with the flag.CommandLine flagset.

func LookupBoolEnv

func LookupBoolEnv(s string) (bool, error)

LookupBoolEnv looks up environment variable s and converts it to a bool.

func LookupDurationEnv

func LookupDurationEnv(s string) (time.Duration, error)

LookupDurationEnv looks up environment variable s and converts it to a time.Duration.

func LookupFloat64Env

func LookupFloat64Env(s string) (float64, error)

LookupFloat64Env looks up environment variable s and converts it to a float64.

func LookupInt64Env

func LookupInt64Env(s string) (int64, error)

LookupInt64Env looks up environment variable s and converts it to an int64.

func LookupIntEnv

func LookupIntEnv(s string) (int, error)

LookupIntEnv looks up environment variable s and converts it to an int64.

func StringVar

func StringVar(target *string, envVar, flagname, defaultval, description string)

StringVar calls FsStringVar with the flag.CommandLine flagset.

Types

This section is empty.

Jump to

Keyboard shortcuts

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