sources

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(schema *schema.Schema, vals *values.Values, ms ...Middleware) error

Execute executes a chain of middlewares to resolve values from multiple sources. It wraps middlewares.ExecuteMiddlewares.

Ordering note: ExecuteMiddlewares reverses the list internally; for the common "call next first" style middlewares, this means the *first* middleware you pass has the *highest* precedence (it runs last and can override), while the *last* middleware you pass has the *lowest* precedence (it runs first).

A typical precedence chain (lowest -> highest) is:

defaults < config files < programmatic map < environment < cobra flags/args

To achieve that, pass middlewares in the *reverse* order:

FromCobra, FromEnv, FromMap, FromFile/FromFiles, FromDefaults

Types

type ConfigFileMapper

type ConfigFileMapper = cmd_middlewares.ConfigFileMapper

ConfigFileMapper is a type alias for middlewares.ConfigFileMapper. It maps arbitrary config file structures into map[layerSlug]map[paramName]value.

type ConfigFileOption

type ConfigFileOption = cmd_middlewares.ConfigFileOption

ConfigFileOption is a type alias for middlewares.ConfigFileOption. It configures how config files are parsed and mapped into layer values.

func WithConfigFileMapper

func WithConfigFileMapper(mapper ConfigFileMapper) ConfigFileOption

WithConfigFileMapper provides a function-based mapper for config file structures. It wraps middlewares.WithConfigFileMapper.

func WithConfigMapper

func WithConfigMapper(mapper ConfigMapper) ConfigFileOption

WithConfigMapper provides a mapper (function-based or pattern-based) for config file structures. It wraps middlewares.WithConfigMapper.

func WithParseOptions

func WithParseOptions(opts ...ParseOption) ConfigFileOption

WithParseOptions configures parse-step options for config-file loading middlewares. It wraps middlewares.WithParseOptions.

type ConfigMapper

type ConfigMapper = cmd_middlewares.ConfigMapper

ConfigMapper is a type alias for middlewares.ConfigMapper (function-based or pattern-based mappers).

type Middleware

type Middleware = cmd_middlewares.Middleware

Middleware is a type alias for middlewares.Middleware. A Middleware resolves values from a source (cobra, env, config, defaults).

func FromArgs

func FromArgs(args []string, opts ...ParseOption) Middleware

FromArgs creates a middleware that parses values from positional arguments. It wraps middlewares.GatherArguments.

func FromCobra

func FromCobra(cmd *cobra.Command, opts ...ParseOption) Middleware

FromCobra creates a middleware that parses values from Cobra command flags. It wraps middlewares.ParseFromCobraCommand.

func FromDefaults

func FromDefaults(opts ...ParseOption) Middleware

FromDefaults creates a middleware that sets default values from field definitions. It wraps middlewares.SetFromDefaults.

func FromEnv

func FromEnv(prefix string, opts ...ParseOption) Middleware

FromEnv creates a middleware that parses values from environment variables. It wraps middlewares.UpdateFromEnv. The prefix is typically the application name (e.g., "APP" becomes "APP_" prefix for env vars).

func FromFile

func FromFile(filename string, opts ...ConfigFileOption) Middleware

FromFile creates a middleware that loads values from a config file (JSON or YAML). It wraps middlewares.LoadParametersFromFile. The config file should have the structure:

layer-slug:
  parameter-name: value

func FromFiles

func FromFiles(files []string, opts ...ConfigFileOption) Middleware

FromFiles creates a middleware that loads values from multiple config files (low -> high precedence). It wraps middlewares.LoadParametersFromFiles.

func FromMap

func FromMap(m map[string]map[string]interface{}, opts ...ParseOption) Middleware

FromMap creates a middleware that sets values from a custom map. It wraps middlewares.UpdateFromMap. The map structure is: map[layerSlug]map[parameterName]value

type ParseOption

type ParseOption = parameters.ParseStepOption

ParseOption is a type alias for parameters.ParseStepOption. Parse options annotate parsed values with source/metadata (useful for debugging and precedence tracking).

func WithMetadata

func WithMetadata(metadata map[string]interface{}) ParseOption

WithMetadata attaches metadata to the parse step (e.g. {"env_key":"APP_FOO"}). It wraps parameters.WithParseStepMetadata.

func WithSource

func WithSource(source string) ParseOption

WithSource sets the parse-step source label (e.g. "env", "flags", "config", "defaults"). It wraps parameters.WithParseStepSource.

Jump to

Keyboard shortcuts

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