flags

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 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 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 LookupEnvBool

func LookupEnvBool(key string, value bool) bool

LookupEnvBool search for given key in environment as bool

func LookupEnvFloat64

func LookupEnvFloat64(key string, value float64) float64

LookupEnvFloat64 search for given key in environment as float64

func LookupEnvInt

func LookupEnvInt(key string, value int) int

LookupEnvInt search for given key in environment as int

func LookupEnvInt64

func LookupEnvInt64(key string, value int64) int64

LookupEnvInt64 search for given key in environment as int64

func LookupEnvString

func LookupEnvString(key, value string) string

LookupEnvString search for given key in environment

func LookupEnvUint

func LookupEnvUint(key string, value uint) uint

LookupEnvUint search for given key in environment as uint

func LookupEnvUint64

func LookupEnvUint64(key string, value uint64) uint64

LookupEnvUint64 search for given key in environment as uint64

func SnakeCase

func SnakeCase(s string) string

SnakeCase transform camelCase to snake_case

Types

type Flag

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

Flag describe a flag

func New

func New(prefix, docPrefix, name string) Flag

New creates new instance of Flag

func (Flag) Default

func (f Flag) Default(value any, overrides []Override) Flag

Default defines default value of Flag

func (Flag) Label

func (f Flag) Label(format string, a ...any) Flag

Label defines label of Flag

func (Flag) ToBool

func (f Flag) ToBool(fs *flag.FlagSet) *bool

ToBool build Flag Set for bool

func (Flag) ToFloat64

func (f Flag) ToFloat64(fs *flag.FlagSet) *float64

ToFloat64 build Flag Set for float64

func (Flag) ToInt

func (f Flag) ToInt(fs *flag.FlagSet) *int

ToInt build Flag Set for int

func (Flag) ToInt64

func (f Flag) ToInt64(fs *flag.FlagSet) *int64

ToInt64 build Flag Set for int64

func (Flag) ToString

func (f Flag) ToString(fs *flag.FlagSet) *string

ToString build Flag Set for string

func (Flag) ToUint

func (f Flag) ToUint(fs *flag.FlagSet) *uint

ToUint build Flag Set for uint

func (Flag) ToUint64

func (f Flag) ToUint64(fs *flag.FlagSet) *uint64

ToUint64 build Flag Set for uint64

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