envutil

package
v0.17.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package envutil provides environment variable helpers with SPROUT_*/LEDIT_* prefix support. This package has ZERO external dependencies to avoid import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the sprout configuration directory path. It mirrors the resolution logic used by the configuration package:

  1. SPROUT_CONFIG / LEDIT_CONFIG environment variable (if set)
  2. XDG_CONFIG_HOME/sprout
  3. HOME/.config/sprout
  4. os.UserHomeDir()/.config/sprout

This lives in envutil (zero external dependencies) so that low-level packages like agent_api can resolve the config directory without importing the configuration package (which would create an import cycle).

func GetEnv

func GetEnv(primaryKey, legacyKey string) string

GetEnv checks for an environment variable using the primary (sproutKey) name first, falling back to the legacy (legacyKey) name. If only the legacy name is set, a one-time deprecation warning is printed to stderr.

func GetEnvSimple

func GetEnvSimple(suffix string) string

GetEnvSimple checks SPROUT_* then LEDIT_* for a variable name suffix. E.g., GetEnvSimple("CONFIG") checks SPROUT_CONFIG then LEDIT_CONFIG.

func HasPrefix

func HasPrefix(name string) bool

HasPrefix checks if an env var name starts with SPROUT_ or LEDIT_.

func LookupEnv

func LookupEnv(suffix string) (string, bool)

LookupEnv checks SPROUT_* first, then LEDIT_*. Returns the value and whether it was found.

func ResolveColorPreference

func ResolveColorPreference(want bool) bool

ResolveColorPreference applies the no-color.org environment overrides to a caller-supplied preference. SP-048-4a.

Precedence (no-color.org-mandated):

  • NO_COLOR set to any non-empty value → colors OFF (always wins)
  • FORCE_COLOR set to any non-empty value → colors ON (unless NO_COLOR)
  • otherwise → caller's want value

Lives in pkg/envutil because pkg/console depends on pkg/configuration (transitively pkg/utils) so pkg/utils can't import pkg/console without creating a cycle. pkg/envutil is the existing zero-dependency leaf used for env-var helpers.

func SetEnv

func SetEnv(suffix, value string) error

SetEnv sets both the SPROUT_* and LEDIT_* versions of an env var.

func SproutKey

func SproutKey(legacyKey string) string

SproutKey returns the SPROUT_* version of a LEDIT_* key.

func UnsetEnv

func UnsetEnv(suffix string)

UnsetEnv removes both SPROUT_* and LEDIT_* versions of an env var.

Types

This section is empty.

Jump to

Keyboard shortcuts

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