dotenv

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatExport added in v1.5.0

func FormatExport(key, value string, shell ShellType) string

FormatExport formats an environment variable for the specified shell

func LoadDotenv

func LoadDotenv(files ...string) error

LoadDotenv loads .env file(s) into the current process environment

func LoadDotenvOverride

func LoadDotenvOverride(files ...string) error

LoadDotenvOverride loads .env file(s) and overrides existing vars

func MustLoadDotenv

func MustLoadDotenv(files ...string)

MustLoadDotenv loads .env file(s) and panics on error

func RunDotenv

func RunDotenv(w io.Writer, args []string, opts DotenvOptions) error

RunDotenv loads environment variables from .env files

Types

type DotenvOptions

type DotenvOptions struct {
	Files    []string  // .env files to load
	Export   bool      // -e: output as export statements
	Quiet    bool      // -q: suppress warnings
	Override bool      // -o: override existing environment variables
	Expand   bool      // -x: expand variables in values
	Shell    ShellType // -s: target shell for export format
}

DotenvOptions configures the dotenv command behavior

type EnvVar

type EnvVar struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

EnvVar represents an environment variable

func ParseDotenv

func ParseDotenv(r io.Reader, opts DotenvOptions) ([]EnvVar, error)

ParseDotenv parses .env content from a reader

func ParseDotenvFile

func ParseDotenvFile(path string, opts DotenvOptions) ([]EnvVar, error)

ParseDotenvFile parses a .env file and returns the variables

type ShellType added in v1.5.0

type ShellType string

ShellType represents a shell type for export format

const (
	ShellAuto       ShellType = "auto"
	ShellBash       ShellType = "bash"
	ShellZsh        ShellType = "zsh"
	ShellFish       ShellType = "fish"
	ShellPowerShell ShellType = "powershell"
	ShellCmd        ShellType = "cmd"
	ShellNuShell    ShellType = "nushell"
)

func DetectShell added in v1.5.0

func DetectShell() ShellType

DetectShell attempts to detect the current shell type from environment

Jump to

Keyboard shortcuts

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