Documentation
¶
Overview ¶
Package env decides what the .env files of a worktree hold — their sync with their source, the ports, the keys wtm owns — and has store write it.
Index ¶
- func AddEnvTargets(ctx context.Context, params AddEnvTargetsParams) error
- func ApplyEnvPorts(ctx context.Context, params EnvPortsParams) (domain.EnvPortPlan, error)
- func ApplyEnvSync(ctx context.Context, params ApplyEnvSyncParams) (domain.EnvSyncResult, error)
- func ApplyOwnedEnv(ctx context.Context, params EnvPortsParams) error
- func ApplyOwnedRestore(ctx context.Context, params OwnedRestoreParams) ([]domain.EnvRestoredEntry, error)
- func ComputeEnvDiff(params ComputeEnvParams) ([]domain.EnvFileResult, error)
- func ComputeEnvPorts(params EnvPortsParams) (domain.EnvPortPlan, error)
- func EnvValueRefsFor(params EnvPortsParams, target string) map[string]rules.EnvValueRef
- func MainEnvValueRepairs(params MainEnvValueRepairsParams) ([]domain.EnvOwnedEntry, error)
- func MissingTargets(params MissingTargetsParams) []domain.EnvMissingFile
- func PlanOwnedRestore(params OwnedRestoreParams) ([]domain.EnvRestoredEntry, error)
- func SyncEnv(ctx context.Context, params SyncEnvParams) (domain.EnvSyncResult, error)
- func WritePortKeys(ctx context.Context, params WritePortKeysParams) ([]domain.PortKeyWrite, error)
- type AddEnvTargetsParams
- type ApplyEnvSyncParams
- type ComputeEnvParams
- type EnvPortsParams
- type EnvResolution
- type MainEnvValueRepairsParams
- type MissingTargetsParams
- type OwnedRestoreParams
- type SyncEnvParams
- type WritePortKeysParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddEnvTargets ¶
func AddEnvTargets(ctx context.Context, params AddEnvTargetsParams) error
AddEnvTargets appends provisioning targets to config.toml as it is on disk.
func ApplyEnvPorts ¶
func ApplyEnvPorts(ctx context.Context, params EnvPortsParams) (domain.EnvPortPlan, error)
ApplyEnvPorts recomputes the plan and writes the rewrites it holds, one file at a time. It returns the plan it acted on, so a caller reports what happened rather than what it intended.
func ApplyEnvSync ¶
func ApplyEnvSync(ctx context.Context, params ApplyEnvSyncParams) (domain.EnvSyncResult, error)
ApplyEnvSync recomputes each file's drift and writes the reconciled content, applying the matching resolution. Files whose reconciled content is unchanged are left untouched. Returns the full result.
func ApplyOwnedEnv ¶
func ApplyOwnedEnv(ctx context.Context, params EnvPortsParams) error
ApplyOwnedEnv writes the worktree identity alone. The port pass is a question the user may answer no to; which worktree this is, is not one of the things being asked.
func ApplyOwnedRestore ¶
func ApplyOwnedRestore(ctx context.Context, params OwnedRestoreParams) ([]domain.EnvRestoredEntry, error)
ApplyOwnedRestore puts the owned keys back to the source's values — what a verbatim worktree's .env holds — and returns what it changed.
func ComputeEnvDiff ¶
func ComputeEnvDiff(params ComputeEnvParams) ([]domain.EnvFileResult, error)
ComputeEnvDiff reconciles every configured env file against its template and value sources and returns the per-file drift, writing nothing. Applied is always false.
func ComputeEnvPorts ¶
func ComputeEnvPorts(params EnvPortsParams) (domain.EnvPortPlan, error)
ComputeEnvPorts resolves every link against the worktree's current .env files, writing nothing. A file that does not exist yields missing keys rather than silence — a link the user declared must stay visible in the report.
func EnvValueRefsFor ¶
func EnvValueRefsFor(params EnvPortsParams, target string) map[string]rules.EnvValueRef
EnvValueRefsFor is how each linked key of one env target may be spelled, which the reconciliation diff needs to compare two worktrees' values.
func MainEnvValueRepairs ¶ added in v0.29.2
func MainEnvValueRepairs(params MainEnvValueRepairsParams) ([]domain.EnvOwnedEntry, error)
MainEnvValueRepairs reads the main checkout's files and their templates for the [env] values wtm once wrote there, and plans putting them back.
func MissingTargets ¶ added in v0.30.0
func MissingTargets(params MissingTargetsParams) []domain.EnvMissingFile
MissingTargets names the declared .env files the worktree lacks, and whether `wtm env` will rebuild each as create would have. It only stats files, so no value can leak from it.
func PlanOwnedRestore ¶
func PlanOwnedRestore(params OwnedRestoreParams) ([]domain.EnvRestoredEntry, error)
PlanOwnedRestore is what putting the owned keys back to the source's values would change, writing nothing.
func SyncEnv ¶
func SyncEnv(ctx context.Context, params SyncEnvParams) (domain.EnvSyncResult, error)
SyncEnv reconciles a worktree's env files non-interactively: it applies safe additions plus any flag-driven decisions (OnConflict, Prune), writing changed files. With Check set it computes and returns the drift without writing anything.
func WritePortKeys ¶
func WritePortKeys(ctx context.Context, params WritePortKeysParams) ([]domain.PortKeyWrite, error)
WritePortKeys materializes each declared port as a .env key, in the value file and in its committed template. It returns what it actually changed, so a report never announces a write the files already held.
The template is only ever amended, never created: adding a committed file nobody asked for is not this pass's business. The value file is created, because provisioning creates it anyway.
Types ¶
type AddEnvTargetsParams ¶
type ApplyEnvSyncParams ¶
type ApplyEnvSyncParams struct {
Branch string
MainPath string
WorktreePath string
ParentWorktreePath string
ParentBranch string
Files []domain.EnvFile
Strategy domain.EnvStrategy
Mode domain.EnvMode
Ports EnvPortsParams
Reserved []string
Resolutions map[string]EnvResolution
}
ApplyEnvSyncParams holds the inputs to apply a set of resolutions to a worktree. Resolutions is keyed by file target; a target with no entry gets the zero resolution (safe additions only — no conflict overwrite, no prune).
type ComputeEnvParams ¶
type ComputeEnvParams struct {
Branch string
MainPath string
WorktreePath string
ParentWorktreePath string
ParentBranch string
Files []domain.EnvFile
Strategy domain.EnvStrategy
Mode domain.EnvMode
Ports EnvPortsParams
Reserved []string
}
ComputeEnvParams holds the inputs to compute a worktree's env drift, without any write. Used by the interactive wizard (to render the drift) and the drift badges.
type EnvPortsParams ¶
type EnvPortsParams struct {
WorktreePath string
Links []domain.EnvPortLink
Bases map[domain.PortRef]int
Offset int
// Block is the spacing between two worktrees' ports, which the reconciliation
// diff needs to recognize another worktree's spelling of the same port.
Block int
// Origins is what turns a port substitution into an address one. A zero
// value plans ports, which is every caller that knows nothing of the proxy.
Origins rules.OriginContext
// Owned are the wtm-derived keys this worktree's .env carries, resolved by
// the caller — the only one that can ask git which worktree this is. The
// [[env]] links resolve into these too: one key wtm writes in full is one
// mechanism, whatever declared it.
Owned []domain.EnvOwnedEntry
// ValueLinks are the [[env]] declarations behind those entries, kept so the
// reconciliation knows which keys it must not call a drift.
ValueLinks []domain.EnvValueLink
// written into the .env unshifted — the service binds what it declares.
Shared map[string]bool
}
EnvPortsParams locates the .env files a set of links names and the offset the worktree binds on. Bases comes from the run config, so this package never reads run.toml itself.
func (EnvPortsParams) Empty ¶
func (p EnvPortsParams) Empty() bool
Empty reports whether the project declares no link at all, which is the common case and means every caller can skip the whole reconciliation.
func (EnvPortsParams) PlanParams ¶ added in v0.30.0
func (p EnvPortsParams) PlanParams() rules.PlanEnvPortsParams
PlanParams is the port plan of these links over no .env yet.
type EnvResolution ¶
type EnvResolution struct {
Decisions map[string]domain.EnvConflictDecision
FilledValues map[string]string
// Prune drops every orphan (the non-interactive --prune); PruneKeys drops only
// the named orphans; SkipKeys omits an addition the user chose not to add
// (per-key choices from the interactive wizard).
Prune bool
PruneKeys map[string]bool
SkipKeys map[string]bool
}
EnvResolution is the decision set for one file: how to settle each conflict, the values supplied for missing/edited keys, and whether to prune orphans. It is produced non-interactively from flags (SyncEnv) or interactively by the wizard (envwizard) and consumed by ApplyEnvSync.
type MainEnvValueRepairsParams ¶ added in v0.29.2
type MainEnvValueRepairsParams struct {
MainPath string
Files []domain.EnvFile
Stamps []domain.EnvOwnedEntry
}
type MissingTargetsParams ¶ added in v0.30.0
type OwnedRestoreParams ¶
type OwnedRestoreParams struct {
MainPath string
WorktreePath string
ParentWorktreePath string
Strategy domain.EnvStrategy
Files []domain.EnvFile
Keys domain.EnvOwnedKeys
}
OwnedRestoreParams locates a worktree, the source its .env files were copied from, and the keys wtm owns in them.
type SyncEnvParams ¶
type SyncEnvParams struct {
Branch string
MainPath string
WorktreePath string
ParentWorktreePath string
ParentBranch string
Files []domain.EnvFile
Strategy domain.EnvStrategy
Mode domain.EnvMode
Ports EnvPortsParams
Reserved []string
Prune bool
Check bool
// OnConflict is the conflict decision applied to every conflict (keep — the safe
// default — or overwrite).
OnConflict domain.EnvConflictDecision
}
SyncEnvParams holds the inputs for the non-interactive reconciliation path (report / JSON / --yes / --check). Interactive resolution goes through ComputeEnvDiff + ApplyEnvSync instead.
type WritePortKeysParams ¶
type WritePortKeysParams struct {
ProjectDir string
Writes []domain.PortKeyWrite
}