envmap

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package envmap flattens a resolved Layer-1 chain into a merged KEY=VALUE environment for the populator (cenvkit run / cenvkit env). It is the no-docker "local arm" of the same chain: pure Go, importing internal/engine for the ONE shared expansion primitive (engine.Flatten) so run/env, env-debug and `docker compose config` all resolve ${VAR} identically (spec §5c, MF4).

envmap itself imports NO compose-go — the seam (only internal/engine touches compose-go) is preserved. It owns the shell-wins overlay and the output formatting (the parts that are pure string handling).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit(w io.Writer, r Resolved, f Format) error

Emit writes the chain-derived keys of r in the requested format, key-sorted (r.ChainKeys is already sorted). Values come from r.Full so a shell override of a chain key is reflected. The emitted set is BOUNDED to chain keys (spec §5e) — the full inherited process env is never dumped.

All three formats are written to be safe to consume: `dotenv` round-trips compose-go's own parser; `shell` is safe to `eval`; `json` is standard JSON.

func EmitDotenv

func EmitDotenv(w io.Writer, r Resolved) error

EmitDotenv writes r as dotenv to w. It is the format `cenvkit run --print` uses (identical content to `cenvkit env --format dotenv`, spec §5d).

Types

type Format

type Format string

Format selects an env emission encoding for `cenvkit env`.

const (
	FormatDotenv Format = "dotenv" // KEY="value"  (round-trips compose-go's dotenv parser)
	FormatJSON   Format = "json"   // a single JSON object {"KEY":"value",...}
	FormatShell  Format = "shell"  // export KEY='value'  (safe to eval)
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat validates a --format value.

type Resolved

type Resolved struct {
	Full      map[string]string // process env + chain (shell-wins); run execs with this
	ChainKeys []string          // sorted keys the chain contributed; env emits only these
}

Resolved is the flattened chain environment. Full is the complete process env with the chain values overlaid SHELL-WINS (what `cenvkit run` execs with). ChainKeys is the sorted set of keys the chain itself contributed — `cenvkit env` emits ONLY these (bounded, reproducible: it must not dump the whole inherited process env into CI logs, spec §5e). The emitted value for a chain key is Full[k], so a shell override of a chain key is reflected.

func Resolve

func Resolve(processEnv map[string]string, files []string, expand bool) (Resolved, error)

Resolve flattens the existence-filtered chain file list into Resolved.

  • expand=true → ${VAR}/${VAR:-default} expand via engine.Flatten (dotenv.GetEnvFromFile); unset ${VAR} with no default → empty (compose parity), not an error.
  • expand=false → literal values, ${...} unexpanded (engine.ParseOrderedLiteral under the hood).

Shell-wins applies IDENTICALLY on both paths: --no-expand suppresses only the ${VAR} expansion, never the overlay (spec §5b). files MUST be existence-filtered (chain.Resolve drops missing); a vanished file (TOCTOU) surfaces as Flatten's error and is fatal to the caller.

Jump to

Keyboard shortcuts

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