gocuelang.org/go/internal/envflag Index | Files

package envflag

import "cuelang.org/go/internal/envflag"

Index

Variables

var ErrInvalid = errors.New("invalid value")

An ErrInvalid indicates a malformed input string.

Functions

func Init

func Init[T any](flags *T, envVar string) error

Init uses Parse with the contents of the given environment variable as input.

func Parse

func Parse[T any](flags *T, env string) error

Parse initializes the fields in flags from the attached struct field tags as well as the contents of the given string.

The struct field tag may contain a default value other than the zero value, such as `envflag:"default:true"` to set a boolean field to true by default.

The tag may be marked as deprecated with `envflag:"deprecated"` which will cause Parse to return an error if the user attempts to set its value to anything but the default value.

The string may contain a comma-separated list of name=value pairs values representing the boolean fields in the struct type T. If the value is omitted entirely, the value is assumed to be name=true.

Names are treated case insensitively. Boolean values are parsed via strconv.ParseBool, integers via strconv.Atoi, and strings are accepted as-is.

Source Files

flag.go

Version
v0.13.0-alpha.3
Published
Mar 31, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
1 minute ago

Tools for package owners.