Documentation
¶
Overview ¶
Package reexec provides shared helpers for re-executing Atmos (either self-replacing the current process or spawning a child) with consistent handling of the --chdir flag and ATMOS_CHDIR environment variable.
Re-exec call sites (version switching, profile fallback, CLI aliases) all need to strip --chdir from argv and ATMOS_CHDIR from env before handing control to the new process — otherwise a relative chdir applied by the parent would be re-applied by the child relative to the already-changed cwd, producing an incorrect or non-existent path.
Index ¶
Constants ¶
const AtmosChdirEnvVar = "ATMOS_CHDIR"
AtmosChdirEnvVar is the environment-variable form of the --chdir flag.
const DepthEnvVar = "ATMOS_REEXEC_DEPTH"
DepthEnvVar holds the re-exec depth counter. A value of 0 (or unset) means the process was not re-exec'd by another Atmos process. A value of 1 or higher means the current process is running inside a re-exec'd child; any code path that would normally trigger another re-exec must short-circuit instead of looping.
Variables ¶
This section is empty.
Functions ¶
func CurrentDepth ¶
func CurrentDepth() int
CurrentDepth reads the current depth from the process environment. It is shorthand for Depth(os.Getenv(DepthEnvVar)) and is the preferred entry point for callers that do not use dependency-injected env lookup.
func Depth ¶
Depth parses a DepthEnvVar value. Empty or non-numeric input returns 0 so callers can treat "missing" and "invalid" identically (both mean "not inside a re-exec").
func FilterChdirEnv ¶
FilterChdirEnv returns a copy of environ with ATMOS_CHDIR removed. When the original contained an ATMOS_CHDIR entry, an explicit empty override (`ATMOS_CHDIR=`) is appended so the child cannot inherit the parent's value via environment merging.
func NextEnv ¶
NextEnv returns a copy of environ with ATMOS_REEXEC_DEPTH incremented by one. If the input contains no depth entry, the returned slice has one appended set to "1". If it contains multiple, the last wins and the returned slice contains exactly one. Use this when building the env slice for a child process about to be re-exec'd.
func StripChdirArgs ¶
StripChdirArgs returns a copy of args with --chdir / -C flags and their values removed. It handles all five accepted forms: `--chdir VAL`, `--chdir=VAL`, `-C VAL`, `-C=VAL`, and `-CVAL` (concatenated).
The POSIX `--` end-of-flags separator is respected: once encountered, the separator and every token that follows are forwarded verbatim so positional arguments intended for downstream tools (terraform, helmfile, packer, custom commands) are never mistaken for atmos flags.
Use this before re-executing Atmos so a chdir that was already applied by the parent is not re-applied by the child against the already-changed working directory.