config

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DirCwd means "the caller's working directory". Use for direct CLI
	// invocations where the user's cwd is the intended config location.
	DirCwd = "."

	// DirProject means "the project directory for this request". Inside the
	// daemon this resolves to the registered project directory via the
	// HUMAN_PROJECT_DIR env var. Outside the daemon it falls back to ".".
	DirProject = "@project"
)

Variables

This section is empty.

Functions

func ApplyEnvOverrides added in v0.12.0

func ApplyEnvOverrides[C any](cfg *C, name, envPrefix string, fields []EnvField[C], lookup EnvLookup)

ApplyEnvOverrides applies environment variable overrides to a config struct. It checks global variables first (PREFIX_SUFFIX), then per-instance variables (PREFIX_NAME_SUFFIX). Per-instance overrides take precedence.

The lookup parameter controls how environment variables are resolved. When nil, os.LookupEnv is used. Pass a custom function to implement per-project scoping or other lookup strategies.

func LoadInstances added in v0.12.0

func LoadInstances[C any, I any](dir string, spec InstanceSpec[C, I]) ([]I, error)

LoadInstances reads configs from a .humanconfig file, applies env overrides, and builds instances using the provided spec.

func ReadProjectName added in v0.18.0

func ReadProjectName(dir string) string

ReadProjectName reads the top-level "project" field from .humanconfig in dir. Returns "" if not set or config is missing.

func ResolveDir added in v0.18.0

func ResolveDir(dir string) string

ResolveDir maps dir sentinel values to real paths. DirProject is resolved via HUMAN_PROJECT_DIR env var (set by the daemon per-request under envMu). All other values pass through unchanged.

func UnmarshalSection

func UnmarshalSection(dir, key string, target any) error

UnmarshalSection reads a .humanconfig YAML file from dir and unmarshals the given key into target. Returns nil when the config file is missing.

Types

type EnvField added in v0.12.0

type EnvField[C any] struct {
	Suffix string
	Set    func(c *C, v string)
	Get    func(c C) string // optional: read the current value (needed for vault resolution)
}

EnvField maps a config struct field to its environment variable suffix. For example, {Suffix: "TOKEN", Set: func(c *MyConfig, v string) { c.Token = v }} will check for PROVIDER_TOKEN (global) and PROVIDER_NAME_TOKEN (per-instance).

type EnvLookup added in v0.18.0

type EnvLookup func(key string) (string, bool)

EnvLookup is a function that looks up an environment variable by key. It returns the value and whether the variable was found, matching the signature of os.LookupEnv.

type InstanceSpec added in v0.12.0

type InstanceSpec[C any, I any] struct {
	// Section is the YAML key in .humanconfig (e.g. "githubs", "jiras").
	Section string

	// EnvPrefix is the prefix for environment variables (e.g. "GITHUB_", "JIRA_").
	EnvPrefix string

	// EnvFields maps config struct fields to env var suffixes.
	EnvFields []EnvField[C]

	// DefaultURL is set on configs with an empty URL before env overrides.
	// Leave empty if no default (e.g. Jira requires explicit URL).
	DefaultURL string

	// Lookup overrides how environment variables are resolved.
	// When nil, os.LookupEnv is used. Set this to a per-project scoped
	// lookup function to support multi-project token isolation.
	Lookup EnvLookup

	// GetName returns the instance name from a config entry.
	GetName func(C) string

	// SetURL sets the URL on the config. Nil if the config has no URL field.
	SetURL func(*C, string)

	// GetURL returns the URL from a config entry. Nil if the config has no URL field.
	GetURL func(C) string

	// Build creates an instance from a config entry. Return (zero, false) to skip
	// the entry (e.g. missing required credentials).
	Build func(C) (I, bool)

	// SecretResolver resolves vault references in config field values.
	// When nil, no vault resolution is performed and values are used as-is.
	// Set this to vault.Resolver.Resolve to enable 1pw:// references.
	SecretResolver SecretResolveFunc
}

InstanceSpec defines how to load and build instances from config entries.

type SecretResolveFunc added in v0.18.0

type SecretResolveFunc func(ref string) (string, error)

SecretResolveFunc resolves a vault reference (e.g. "1pw://vault/item/field") to its plaintext value. Non-references are returned unchanged.

Jump to

Keyboard shortcuts

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