env

package
v0.0.0-...-3ffe2d3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFlagRequired error = errors.New("the flag is required")
)

Functions

func Parse

func Parse(flags Flags) error

Parse the passed flags

Types

type BaseFlag

type BaseFlag[T interfaces.Ordered] struct {
	// Value is the address of some variable, which can be some pkg variable, for example
	Value *T

	// Default is the default value to assign to this variable
	Default T

	// EnvName is the name of the environment variable that will try to fetch this data
	EnvName string

	// Required is used to check if the value was found in the path.
	// This is necessary, since that an empty variable can be in the env
	Required bool
}

BaseFlag can be used for the BaseFlagTypes only.

If you don't pass a Default value, the variable will be mandatory

func (*BaseFlag[T]) Apply

func (s *BaseFlag[T]) Apply() error

func (*BaseFlag[T]) CurrentValue

func (s *BaseFlag[T]) CurrentValue() any

func (*BaseFlag[T]) DefaultValue

func (s *BaseFlag[T]) DefaultValue() any

func (*BaseFlag[T]) IsRequired

func (s *BaseFlag[T]) IsRequired() bool

func (*BaseFlag[T]) Name

func (s *BaseFlag[T]) Name() string

func (*BaseFlag[T]) String

func (s *BaseFlag[T]) String() string

type Flag

type Flag interface {
	Apply() error
	fmt.Stringer
	Name() string
	CurrentValue() any
	IsRequired() bool
	DefaultValue() any
}

type Flags

type Flags []Flag

func (Flags) String

func (s Flags) String() string

Jump to

Keyboard shortcuts

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