env

package
v0.0.0-...-cd3ace8 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Default is the default set of environment variable set, parsed from os.Environment().

View Source
var Usage = func() string {
	return Default.Usage()
}

Usage returns Default.Usage().

Functions

func Bool

func Bool(name string, def bool, usage string) *bool

Bool defines a bool value with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.

func BoolVar

func BoolVar(p *bool, name string, def bool, usage string)

BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.

func Int

func Int(name string, def int, usage string) *int

Int defines a int value with specified name, default value, and usage string. The return value is the address of a int variable that stores the value of the environment variable.

func IntVar

func IntVar(p *int, name string, def int, usage string)

IntVar defines a int environment variable with specified name, default value, and usage string. The argument p points to a int variable in which to store the value of the environment variable.

func Parse

func Parse()

Parse parses the environment variables from os.Environ(). Must be called after all variables are defined and before variable are accessed by the program.

func String

func String(name string, def string, usage string) *string

String defines a string value with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.

func StringVar

func StringVar(p *string, name string, def string, usage string)

StringVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the environment variable.

Types

type ErrorHandling

type ErrorHandling int

ErrorHandling defines how VariableSet.Parse behaves if the parse fails.

const (
	ContinueOnError ErrorHandling = iota // Return a descriptive error.
	ExitOnError                          // Call os.Exit(2).
	PanicOnError                         // Call panic with a descriptive error.
)

These constants cause VariableSet.Parse to behave as described if the parse fails.

type Value

type Value interface {
	Set(v string) error
}

Value is the interface to the dynamic value stored in a value.

type VariableSet

type VariableSet struct {
	Usage func() string
	// contains filtered or unexported fields
}

A VariableSet represents a set of defined environment variable. The zero value of a FlagSet has no name and has ContinueOnError error handling.

Flag names must be unique within a FlagSet. An attempt to define a flag whose name is already in use will cause a panic.

func NewVariableSet

func NewVariableSet(name string, handling ErrorHandling) *VariableSet

NewVariableSet returns a new, empty variable set with the specified name and error handling property. If the name is not empty, it will be printed in the default usage message and in error messages.

func (*VariableSet) Bool

func (set *VariableSet) Bool(name string, def bool, usage string) *bool

Bool defines a bool value with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.

func (*VariableSet) BoolVar

func (set *VariableSet) BoolVar(p *bool, name string, def bool, usage string)

BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.

func (*VariableSet) Int

func (set *VariableSet) Int(name string, def int, usage string) *int

Int defines a int value with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.

func (*VariableSet) IntVar

func (set *VariableSet) IntVar(p *int, name string, def int, usage string)

IntVar defines a int environment variable with specified name, default value, and usage string. The argument p points to a int variable in which to store the value of the environment variable.

func (*VariableSet) Parse

func (set *VariableSet) Parse(environments []string) error

Parse parses the environment variables from argument. Must be called after all variables are defined and before variable are accessed by the program.

func (*VariableSet) String

func (set *VariableSet) String(name string, def string, usage string) *string

String defines a string value with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.

func (*VariableSet) StringVar

func (set *VariableSet) StringVar(p *string, name string, def string, usage string)

StringVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the environment variable.

Jump to

Keyboard shortcuts

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