projectroot

package
v1.233.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
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

func FindConfigInParentDirs(startDir string) string

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

func HasLocalConfig(dir string) bool

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

func SearchDirs(cwd string, args []string) []string

SearchDirs returns the directories that supply project-level files for cwd, highest precedence first, mirroring the effective atmos.yaml discovery:

  1. Directories of --config / --config-path (flags in args, then ATMOS_CONFIG / ATMOS_CONFIG_PATH). When any is selected, discovery stops there.
  2. The directory of ATMOS_CLI_CONFIG_PATH, when set (a file path resolves to its directory).
  3. cwd.
  4. 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

type ConfigSelection struct {
	BasePath   string
	Config     []string
	ConfigPath []string
}

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.

Jump to

Keyboard shortcuts

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