envflag

package module
v0.0.0-...-e878ff5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 5 Imported by: 0

README

Environment variables and flags

Set flags using Go's flag package, and complement them with environment variables.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleFlag

func ExampleFlag()

func ExampleFlagSet

func ExampleFlagSet()

func Parse

func Parse(opts ...Option) error

ParseWithEnv parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.

func ParseFlagSet

func ParseFlagSet(fs *flag.FlagSet, arguments []string, opts ...Option) error

ParseFlagSetWithEnv parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help or -h were set but not defined.

Types

type FlagConverterFunc

type FlagConverterFunc func(flag string) string

FlagConverterFunc functions are used to update flag name for envvar lookups.

type Option

type Option option

Option type for configing the parsing.

func FlagConverter

func FlagConverter(f FlagConverterFunc) Option

FlagConverter converts the flag name to an environment variable key.

func UsagePrefixer

func UsagePrefixer() Option

UsagePrefixer prefixes the flag usage with [envvar].

func UsageSuffixer

func UsageSuffixer() Option

UsageSuffixer suffixes the flag usage with [envvar].

func UsageUpdater

func UsageUpdater(f UsageUpdaterFunc) Option

UsageUpdater enables configurable flag usage updates.

type UsageUpdaterFunc

type UsageUpdaterFunc func(key, usage string) string

UsageUpdaterFunc functions are used to update flag usage strings.

Source Files

  • example.go
  • flag.go

Jump to

Keyboard shortcuts

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