flags

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 7 Imported by: 91

README

flags

Build codecov Quality Gate Status

Golang flags parser with zero dependency.

Usage

See simple.go for basic usage.

Concept

flags gives a simple way to get flag's value from argument or environment variable.

Argument takes priority over environment variable. Argument and environment variable names are generated from configuration you pass.

The FlagSet name is used to prefix all environment variable, replacing - by _.

The prefix name is used then to specialize your flag name (e.g. if you have want to use the same flags twice, you can change the prefix)

The argument's name is in camelCase format. The environement variable name is in SNAKE_UPPER_CASE format.

Flags can take a default value, that can be overriden programatically, always in the case you reuse the same flags twice (see advanced.go example.)

Security

Be careful when using the arguments values, if someone list the processes on the system, they will appear in plain-text. Pass secrets by environment variables: it's less easily visible.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v1.0.0

func Bool(fs *flag.FlagSet, prefix, docPrefix, name, label string, value bool, overrides []Override) *bool

Bool creates a bool flag

func FirstLowerCase

func FirstLowerCase(s string) string

FirstLowerCase change first letter to lowerCase

func FirstUpperCase

func FirstUpperCase(s string) string

FirstUpperCase change first letter to UpperCase

func Float64 added in v1.0.0

func Float64(fs *flag.FlagSet, prefix, docPrefix, name, label string, value float64, overrides []Override) *float64

Float64 creates a float64 flag

func Int added in v1.0.0

func Int(fs *flag.FlagSet, prefix, docPrefix, name, label string, value int, overrides []Override) *int

Int creates a int flag

func Int64 added in v1.0.0

func Int64(fs *flag.FlagSet, prefix, docPrefix, name, label string, value int64, overrides []Override) *int64

Int64 creates a int64 flag

func LookupEnvBool

func LookupEnvBool(name, envName string, value bool, overrides []Override) bool

LookupEnvBool search for given key in environment as bool

func LookupEnvFloat64

func LookupEnvFloat64(name, envName string, value float64, overrides []Override) float64

LookupEnvFloat64 search for given key in environment as float64

func LookupEnvInt

func LookupEnvInt(name, envName string, value int, overrides []Override) int

LookupEnvInt search for given key in environment as int

func LookupEnvInt64

func LookupEnvInt64(name, envName string, value int64, overrides []Override) int64

LookupEnvInt64 search for given key in environment as int64

func LookupEnvString

func LookupEnvString(name, envName string, value string, overrides []Override) string

LookupEnvString search for given key in environment

func LookupEnvUint

func LookupEnvUint(name, envName string, value uint, overrides []Override) uint

LookupEnvUint search for given key in environment as uint

func LookupEnvUint64

func LookupEnvUint64(name, envName string, value uint64, overrides []Override) uint64

LookupEnvUint64 search for given key in environment as uint64

func SnakeCase

func SnakeCase(s string) string

SnakeCase transform camelCase to snake_case

func String added in v1.0.0

func String(fs *flag.FlagSet, prefix, docPrefix, name, label string, value string, overrides []Override) *string

String creates a string flag

func Uint added in v1.0.0

func Uint(fs *flag.FlagSet, prefix, docPrefix, name, label string, value uint, overrides []Override) *uint

Uint creates a uint flag

func Uint64 added in v1.0.0

func Uint64(fs *flag.FlagSet, prefix, docPrefix, name, label string, value uint64, overrides []Override) *uint64

Uint64 creates a uint64 flag

Types

type Override

type Override struct {
	// contains filtered or unexported fields
}

Override is an override of default value

func NewOverride

func NewOverride(name string, value any) Override

NewOverride create a default override value

Directories

Path Synopsis
cmd
advanced command
simple command

Jump to

Keyboard shortcuts

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