envflag

package
v2.0.205+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: MIT Imports: 3 Imported by: 15

Documentation

Overview

Package envflag implements support for setting flags through environment variables. Unlike the package standard flag package, a set of top-level wrapper functions are not provided.

Example
Output:

mysql.example:3306
redis.example:6379
http://localhost/ping
nobody

Index

Examples

Constants

This section is empty.

Variables

View Source
var CommandLine = NewFlagSet(flag.CommandLine)

CommandLine is the default set of env flags, backed by the default set of command-line flags. The top-level functions of this package are wrappers for the methods of CommandLine.

Functions

This section is empty.

Types

type FlagSet

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

FlagSet represents a set of defined env flags.

func NewFlagSet

func NewFlagSet(fs *flag.FlagSet) *FlagSet

NewFlagSet returns a new, empty flag set.

func (*FlagSet) Parse

func (fs *FlagSet) Parse()

Parse parses configuration from environment variables and stores non-empty values. It is recommended to call this after all flags are defined and before flag.FlagSet.Parse.

func (*FlagSet) String

func (fs *FlagSet) String(flagName, envvarName, value, usage string) *string

String defines a string flag. A string flag is a single string value, parsed either from an environment variable "<envvarName>" or a command-line argument "-<flagName". The return value is the address of a string variable that stores the value of the flag.

This is a general flag creation utility which is why flagName and envvarName are provided separately rather than generated from a common base.

Example
Output:

callback

Jump to

Keyboard shortcuts

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