Documentation
¶
Overview ¶
Package projectroot selects the directory that supplies project-level files (atmos.yaml, policy.d) for a working directory.
It is a leaf package so both configuration loading (pkg/config) and policy discovery (pkg/policy), which pkg/config depends on, share one definition of the project root. It never reads or parses any project file.
Index ¶
Constants ¶
const ( // AtmosConfigFileName is the main config file name. AtmosConfigFileName = "atmos.yaml" // DotAtmosConfigFileName is the hidden config file name. DotAtmosConfigFileName = ".atmos.yaml" // AtmosConfigDirName is the config directory name. AtmosConfigDirName = ".atmos" // AtmosDefaultImportsDirName is the default imports directory name. AtmosDefaultImportsDirName = "atmos.d" // DotAtmosDefaultImportsDirName is the hidden default imports directory name. DotAtmosDefaultImportsDirName = ".atmos.d" // CliConfigPathEnvVar is the environment variable naming an explicit config location. CliConfigPathEnvVar = "ATMOS_CLI_CONFIG_PATH" // GitRootBasePathEnvVar disables Git root discovery when set to "false". GitRootBasePathEnvVar = "ATMOS_GIT_ROOT_BASEPATH" )
Variables ¶
This section is empty.
Functions ¶
func FindConfigInParentDirs ¶
FindConfigInParentDirs searches for atmos.yaml in parent directories. It walks up the directory tree from the given starting directory until it finds an atmos.yaml file or reaches the filesystem root. Returns the directory containing atmos.yaml, or empty string if not found.
func GitRootDiscoveryDisabled ¶
func GitRootDiscoveryDisabled() bool
GitRootDiscoveryDisabled reports whether ATMOS_GIT_ROOT_BASEPATH=false.
func HasLocalConfig ¶
HasLocalConfig reports whether dir has any Atmos configuration.
Returns true if ANY of these exist in the given directory: - atmos.yaml (main config file) - .atmos.yaml (hidden config file) - .atmos/ (config directory) - .atmos.d/ (default imports directory) - atmos.d/ (default imports directory - alternate).
func SearchDirs ¶
SearchDirs returns the directories that supply project-level files for cwd, highest precedence first, mirroring the effective atmos.yaml discovery:
- Directories of --config / --config-path (flags in args, then ATMOS_CONFIG / ATMOS_CONFIG_PATH). When any is selected, discovery stops there.
- The directory of ATMOS_CLI_CONFIG_PATH, when set (a file path resolves to its directory).
- cwd.
- Unless cwd has local Atmos configuration, or step 1 or 2 applied: the Git repository root (skipped with ATMOS_GIT_ROOT_BASEPATH=false), then the nearest ancestor holding atmos.yaml. Config loading reads both, so both can supply project-level files, as in a monorepo whose atmos.yaml and policy.d sit in a subdirectory of the repository.
cwd is included even when config selection applies, so a policy.d next to the working directory is never silently dropped. Callers use the first directory that has the file they need.
Types ¶
type ConfigSelection ¶
ConfigSelection holds the config-selection flags parsed early from os.Args before Cobra is initialized (same pattern as profile early-parsing).
func ConfigSelectionFromEnv ¶
func ConfigSelectionFromEnv() ConfigSelection
ConfigSelectionFromEnv reads config-selection values from environment variables as fallbacks when not provided via CLI flags.
func ParseConfigSelectionFromOsArgs ¶
func ParseConfigSelectionFromOsArgs(args []string) ConfigSelection
ParseConfigSelectionFromOsArgs parses --base-path, --config, and --config-path flags from os.Args. This is used for early extraction before Cobra parses flags, so that InitCliConfig receives the correct config location.
func (*ConfigSelection) ApplyFallbacks ¶
func (s *ConfigSelection) ApplyFallbacks(fallback ConfigSelection)
ApplyFallbacks fills each unset field from fallback, so flags win over env.