settings

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package settings resolves the tool's runtime settings from five layers.

Precedence, lowest first:

defaults < pack config `settings` < global config < ICHAVA_* env < flags

Each layer is a partial set of values keyed by a dotted name ("git.base"). Resolution records which layer supplied every value, so `config print` can say why a value is what it is -- the question that matters when a scheduled run behaves differently from a laptop.

The key registry below is the single list of what can be set. A layer that names a key not in it is an error rather than an ignored typo: a misspelt `dry_rnu: true` that silently did nothing would commit and open a pull request the operator had asked not to.

Index

Constants

View Source
const (
	DefaultAuthor          = "ichava-sync-bot <19682005+imanimanyara@users.noreply.github.com>"
	DefaultBase            = "main"
	DefaultBranch          = "chore/sync-upstream-{version}"
	DefaultCommitSubject   = "chore(upstream): bump {pack} to v{new}"
	DefaultCommitBody      = "" /* 138-byte string literal not displayed */
	DefaultUnicodeVersion  = "16.0"
	DefaultOpenMojiVersion = "15.1.0"
)

Defaults that other packages also declare. They are duplicated rather than imported to keep this package free of the pipeline layer; settings_test pins each one against its source of truth.

View Source
const AppDir = "icon-sets-sync"

AppDir is the directory name under the XDG config home.

View Source
const GlobalConfigEnv = "ICHAVA_GLOBAL_CONFIG"

GlobalConfigEnv points at a global config file explicitly, overriding the XDG lookup. --global-config does the same from the command line.

Variables

View Source
var Keys = []Key{
	{Name: "config_dir", Kind: String, Default: "", Env: "ICHAVA_CONFIG_DIR", LegacyEnv: []string{"ICHAVA_DEV_CONFIG_DIR"},
		Help: "directory holding packs.json and the pack configs (default: config/ beside the binary, else ./config)"},
	{Name: "private_config_dir", Kind: String, Default: "", Env: "ICHAVA_PRIVATE_CONFIG_DIR",
		Help: "directory of private pack configs merged over config_dir at run time (packs.json optional; none by default)"},
	{Name: "log_level", Kind: String, Default: "info", Env: "ICHAVA_LOG_LEVEL", LegacyEnv: []string{"ICHAVA_DEV_LOG_LEVEL"},
		Enum: []string{"debug", "info", "warn", "error"}, Help: "log verbosity; -v is debug, -q is error"},
	{Name: "concurrency", Kind: Int, Default: 1, Env: "ICHAVA_CONCURRENCY", Min: 1,
		Help: "packs synced at once by sync --all / sync-all"},
	{Name: "workspace", Kind: String, Default: "", Env: "ICHAVA_WORKSPACE",
		Help: "directory a relative pack_root is resolved against"},
	{Name: "dry_run", Kind: Bool, Default: false, Env: "ICHAVA_DRY_RUN", PackScoped: true,
		Help: "refresh files but skip the version stamp, commit, push and pull request"},
	{Name: "force", Kind: Bool, Default: false, Env: "ICHAVA_FORCE", PackScoped: true,
		Help: "refresh even when the pack is not behind upstream"},
	{Name: "git.author", Kind: String, Default: DefaultAuthor, Env: "ICHAVA_GIT_AUTHOR", PackScoped: true,
		Pattern: regexp.MustCompile(`^[^<>]+ <[^<>@]+@[^<>]+>$`),
		Help:    "author and committer of sync commits, as `Name <email>`"},
	{Name: "git.base", Kind: String, Default: DefaultBase, Env: "ICHAVA_GIT_BASE", PackScoped: true,
		Help: "base branch the pull request targets"},
	{Name: "git.branch", Kind: String, Default: DefaultBranch, Env: "ICHAVA_GIT_BRANCH", PackScoped: true,
		Help: "sync branch; {version} is the upstream version"},
	{Name: "git.commit_subject", Kind: String, Default: DefaultCommitSubject, Env: "ICHAVA_GIT_COMMIT_SUBJECT", PackScoped: true,
		Help: "commit and PR title; {pack}, {old}, {new} are interpolated"},
	{Name: "git.commit_body", Kind: String, Default: DefaultCommitBody, Env: "ICHAVA_GIT_COMMIT_BODY", PackScoped: true,
		Help: "commit and PR body; same tokens as the subject"},
	{Name: "git.open_pr", Kind: Bool, Default: true, Env: "ICHAVA_GIT_OPEN_PR", PackScoped: true,
		Help: "open a pull request after pushing"},
	{Name: "emoji.unicode_version", Kind: String, Default: DefaultUnicodeVersion, Env: "ICHAVA_EMOJI_UNICODE_VERSION", PackScoped: true,
		Help: "Unicode emoji release whose emoji-test.txt drives categorisation; must exist at unicode.org/Public/emoji/"},
	{Name: "emoji.openmoji_version", Kind: String, Default: DefaultOpenMojiVersion, Env: "ICHAVA_EMOJI_OPENMOJI_VERSION", PackScoped: true,
		Help: "OpenMoji release tag for the emoji recipe"},
}

Keys is the registry, in display order.

Precedence lists the layers lowest first. Resolve applies them in this order.

Functions

func GlobalConfigPath

func GlobalConfigPath(lookup func(string) (string, bool)) (string, error)

GlobalConfigPath finds the optional global config file.

$XDG_CONFIG_HOME/icon-sets-sync/config.{json,yaml,yml}, falling back to ~/.config when XDG_CONFIG_HOME is unset -- on macOS too, per the house rule that config lives where a person expects to find it. Returns "" with no error when there is none: the file is optional, and a fresh machine or a CI container has none.

func Names

func Names() []string

Names returns every key name, sorted.

Types

type Emoji

type Emoji struct {
	UnicodeVersion  string
	OpenMojiVersion string
}

Emoji is the emoji recipe's upstream versions.

type Git

type Git struct {
	Author        string
	Base          string
	Branch        string
	CommitSubject string
	CommitBody    string
	OpenPR        bool
}

Git is the git and pull-request settings.

type Key

type Key struct {
	// Name is the dotted name used in config files, --set and output.
	Name string
	Kind Kind

	// Default is the value when no layer sets it.
	Default any

	// Env is the environment variable that sets it. LegacyEnv lists older
	// names still honoured, lower precedence than Env.
	Env       string
	LegacyEnv []string

	// PackScoped keys may appear in a pack config's `settings`. Run-wide keys
	// (where configs live, how many packs run at once, how loud the log is)
	// cannot: one pack cannot meaningfully decide them for a run of four.
	PackScoped bool

	// Enum restricts a string to these values. Min bounds an integer.
	Enum []string
	Min  int

	// Pattern, when set, must match a string value.
	Pattern *regexp.Regexp

	Help string
}

Key describes one setting.

func Lookup

func Lookup(name string) (Key, bool)

Lookup returns the key with this name.

func (Key) ParseString

func (k Key) ParseString(raw string) (any, error)

ParseString converts a raw string (from the environment or --set) to the key's type.

type Kind

type Kind int

Kind is a setting's value type.

const (
	String Kind = iota
	Bool
	Int
)

The value types a setting can hold.

func (Kind) String

func (k Kind) String() string

type Layer

type Layer string

Layer names where a value came from.

const (
	LayerDefault Layer = "default"
	LayerPack    Layer = "pack"
	LayerGlobal  Layer = "global"
	LayerEnv     Layer = "env"
	LayerFlag    Layer = "flag"
)

The five layers, as reported by Origin.

type LayerValues

type LayerValues struct {
	Layer  Layer
	Values Values
}

LayerValues pairs a layer with its values, for Resolve.

type Resolved

type Resolved struct {
	// contains filtered or unexported fields
}

Resolved is the merged result, with the layer each value came from.

func Resolve

func Resolve(layers ...LayerValues) Resolved

Resolve merges layers over the defaults. Pass them lowest precedence first; a later layer replaces an earlier one key by key.

func (Resolved) Bool

func (r Resolved) Bool(name string) bool

Bool returns a boolean setting.

func (Resolved) FromAbove

func (r Resolved) FromAbove(name string) bool

FromAbove reports whether a value was set above the pack layer -- by the global config, the environment or a flag. A per-sink field in a pack config is pack-layer too, and gives way only to these.

func (Resolved) Int

func (r Resolved) Int(name string) int

Int returns an integer setting.

func (Resolved) Origin

func (r Resolved) Origin(name string) Layer

Origin returns the layer that supplied a value.

func (Resolved) Origins

func (r Resolved) Origins() map[string]string

Origins returns name -> layer for every key.

func (Resolved) Settings

func (r Resolved) Settings() Settings

Settings returns the typed view.

func (Resolved) String

func (r Resolved) String(name string) string

String returns a string setting. It panics on an unknown name, which is a programming error rather than a configuration one.

func (Resolved) Tree

func (r Resolved) Tree() map[string]any

Tree returns the values as a nested map, for printing.

type Settings

type Settings struct {
	ConfigDir        string
	PrivateConfigDir string
	LogLevel         string
	Concurrency      int
	Workspace        string
	DryRun           bool
	Force            bool
	Git              Git
	Emoji            Emoji
}

Settings is the typed view of a resolution.

type Stack

type Stack struct {
	Global Values
	Env    Values
	Flags  Values
}

Stack holds the layers that do not vary by pack.

func (Stack) Resolve

func (s Stack) Resolve(pack Values) Resolved

Resolve merges the stack over one pack's values (nil for run-wide settings), in the documented precedence.

type Values

type Values map[string]any

Values is a partial layer: only the keys that layer sets.

func FromAssignments

func FromAssignments(pairs []string) (Values, error)

FromAssignments parses --set key=value pairs.

func FromEnv

func FromEnv(lookup func(string) (string, bool)) (Values, error)

FromEnv reads every key's environment variable. An empty variable is unset. The current name wins over a legacy one.

func FromTree

func FromTree(tree map[string]any, layer Layer) (Values, error)

FromTree flattens a nested document (a config file's contents) into a layer.

Top-level keys beginning with "_" are authoring notes and are skipped, as in the pack configs. For LayerPack, a run-wide key is an error.

func LoadGlobal

func LoadGlobal(path string) (Values, error)

LoadGlobal reads a global config file into the global layer.

func ParseGlobal added in v0.1.1

func ParseGlobal(path string, data []byte) (Values, error)

ParseGlobal is LoadGlobal on bytes already in hand, so an editor validates a global config with the loader that will read it.

func (Values) Set

func (v Values) Set(name string, value any) error

Set validates and stores one value.

Jump to

Keyboard shortcuts

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