envfile

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ComposeProjectNameEnvKey = "COMPOSE_PROJECT_NAME"

ComposeProjectNameEnvKey is the host-side Docker Compose project name written to the project .env (not .env.local). Compose loads .env automatically when commands run with Dir = project root.

Variables

This section is empty.

Functions

func ExtractComposeProjectName

func ExtractComposeProjectName(envContent []byte) string

ExtractComposeProjectName returns the COMPOSE_PROJECT_NAME value from raw dotenv content, or "" when unset.

func ExtractEnvVar

func ExtractEnvVar(content []byte, key string) string

ExtractEnvVar returns the value of key in raw dotenv content, or "" when unset. Blank and comment lines are skipped, whitespace around key and value is trimmed, and the first assignment wins.

func LoadSymfonyEnvFile

func LoadSymfonyEnvFile(projectRoot string) error

LoadSymfonyEnvFile loads the Symfony .env file from the project root.

func ReadAll

func ReadAll(projectRoot string) (map[string]string, error)

ReadAll returns every variable defined across the project's Symfony env files, merged with Symfony precedence (.env.dist < .env < .env.local). An empty map is returned when no env file exists.

func ReadAllForEnvironment

func ReadAllForEnvironment(projectRoot, environment string) (map[string]string, error)

ReadAllForEnvironment is like ReadAll but additionally layers the environment-specific files on top, following Symfony precedence (.env.dist < .env < .env.local < .env.<env> < .env.<env>.local). An empty environment behaves exactly like ReadAll.

func ReadComposeProjectName

func ReadComposeProjectName(projectRoot string) string

ReadComposeProjectName returns the COMPOSE_PROJECT_NAME configured in the project's .env, or "" when the file or the key is missing.

func ReadEnvVar

func ReadEnvVar(path, key string) string

ReadEnvVar returns the value of key in the env file at path, or "" when the file or the key does not exist.

func ReadValue

func ReadValue(projectRoot, key string) (string, error)

ReadValue returns the effective value of key in the project's Symfony env files. Precedence follows Symfony: .env.dist < .env < .env.local. An empty string is returned when the key is undefined or no env file exists.

func ReadValues

func ReadValues(projectRoot string, keys ...string) (map[string]string, error)

ReadValues returns the resolved values for the requested keys. The returned map always contains every requested key; missing keys map to "".

func UpsertEnvVar

func UpsertEnvVar(path, key, value string) error

UpsertEnvVar sets key to value in the env file at path, replacing an existing assignment or appending one. The file is created when missing; all other lines are preserved as-is.

func WriteValue

func WriteValue(projectRoot, key, value string) error

WriteValue is a convenience wrapper around WriteValues for a single key.

func WriteValues

func WriteValues(projectRoot string, values map[string]string) error

WriteValues persists all entries into .env.local. Existing assignments are replaced in place to preserve surrounding lines, comments and formatting; missing keys are appended in deterministic (sorted) order. The file is created when it does not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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