config

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads user configuration from ~/.kunji/config.yaml and applies profile / environment overrides to cobra flag defaults.

Resolution order, highest priority first:

  1. CLI flag passed on the command line (handled by cobra during parsing)
  2. KUNJI_<FLAG_UPPER> environment variable
  3. The active profile's value for that flag
  4. The built-in default registered with the flag

"Active profile" is determined by:

  1. --profile <name> on the command line
  2. KUNJI_PROFILE environment variable
  3. default_profile field in the config file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the location we look for config at. Resolution order:

KUNJI_CONFIG env var (explicit override)
~/.kunji/config.yaml
.kunji/config.yaml (cwd fallback)

Types

type Config

type Config struct {
	Path string
	// contains filtered or unexported fields
}

Config holds the parsed config plus the path it was loaded from. A zero Config (Path == "") is valid and means "no config file present".

func Cached

func Cached() (*Config, error)

func Load

func Load() (*Config, error)

Load reads the config file at DefaultPath(). A missing file is not an error — it returns an empty Config so callers can use Apply unconditionally. Parse errors are returned so the user can fix a malformed config.

func LoadFrom

func LoadFrom(path string) (*Config, error)

LoadFrom is Load for a specific path. Useful in tests.

func (*Config) ActiveProfileName

func (c *Config) ActiveProfileName(cliProfile string) string

ActiveProfileName returns the profile to use. Resolution order:

--profile flag value (passed in via cliProfile)
KUNJI_PROFILE env var
default_profile from the config
"" (caller treats this as "no profile")

func (*Config) Apply

func (c *Config) Apply(root *cobra.Command, cliProfile string)

Apply walks the cobra command tree (rootCmd and every descendant) and overrides each flag's default with the value from the active profile or the environment. CLI flags passed on the command line still win because cobra only falls back to the default when a flag was not provided.

The env-var-name for a flag "foo-bar" is "KUNJI_FOO_BAR".

func (*Config) Lookup

func (c *Config) Lookup(profileName, key string) (interface{}, bool)

Lookup returns the value for key from the active profile (or the top-level default block if profileName is ""), and a found flag. Lookup returns the value for key from the active profile (or the top-level default block if profileName is ""), and a found flag.

Keys are normalized: dashes and underscores are interchangeable so users can write either `only_valid: true` or `only-valid: true` in YAML.

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns the configured profile names sorted alphabetically.

Jump to

Keyboard shortcuts

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