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
- Variables
- func GlobalConfigPath(lookup func(string) (string, bool)) (string, error)
- func Names() []string
- type Emoji
- type Git
- type Key
- type Kind
- type Layer
- type LayerValues
- type Resolved
- func (r Resolved) Bool(name string) bool
- func (r Resolved) FromAbove(name string) bool
- func (r Resolved) Int(name string) int
- func (r Resolved) Origin(name string) Layer
- func (r Resolved) Origins() map[string]string
- func (r Resolved) Settings() Settings
- func (r Resolved) String(name string) string
- func (r Resolved) Tree() map[string]any
- type Settings
- type Stack
- type Values
Constants ¶
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.
const AppDir = "icon-sets-sync"
AppDir is the directory name under the XDG config home.
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 ¶
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: "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.
var Precedence = []Layer{LayerDefault, LayerPack, LayerGlobal, LayerEnv, LayerFlag}
Precedence lists the layers lowest first. Resolve applies them in this order.
Functions ¶
func GlobalConfigPath ¶
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.
Types ¶
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.
type LayerValues ¶
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) FromAbove ¶
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.
type Settings ¶
type Settings struct {
ConfigDir string
LogLevel string
Concurrency int
Workspace string
DryRun bool
Force bool
Git Git
Emoji Emoji
}
Settings is the typed view of a resolution.
type Values ¶
Values is a partial layer: only the keys that layer sets.
func FromAssignments ¶
FromAssignments parses --set key=value pairs.
func FromEnv ¶
FromEnv reads every key's environment variable. An empty variable is unset. The current name wins over a legacy one.
func FromTree ¶
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 ¶
LoadGlobal reads a global config file into the global layer.
func ParseGlobal ¶ added in v0.1.1
ParseGlobal is LoadGlobal on bytes already in hand, so an editor validates a global config with the loader that will read it.