settings

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 13 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 (
	TLSAuto           = "auto"
	TLSOffBehindProxy = "off-behind-proxy"
)

TLS modes for api.tls. Auto terminates TLS whenever serve binds beyond loopback; OffBehindProxy serves plain HTTP there, for a TLS proxy in front.

View Source
const (
	DefaultAuthor         = "ichava-sync-bot <41898282+github-actions[bot]@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"
)

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.

View Source
const GlobalSchemaURL = "https://raw.githubusercontent.com/ichava/icon-sets-sync/main/config/schema/global.schema.json"

GlobalSchemaURL is the $schema a global config names, so an editor offers completion and checks it. It is the file GlobalSchema generates, as published on the default branch.

View Source
const GroupIntegrations = "integrations"

GroupIntegrations is the Settings page section of the integration keys.

Variables

View Source
var ErrNoWebhook = errors.New("no such webhook")

ErrNoWebhook is returned for a webhook name webhooks.endpoints lacks.

View Source
var Keys = []Key{
	{Name: "config_dir", Kind: String, Default: "", Env: "ICHAVA_CONFIG_DIR",
		Help: "directory holding packs.json and the pack configs (default: config/ beside the binary, else ./config when it holds packs.json, else the config/ of the repository around the working directory, up to 5 levels)"},
	{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",
		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: "allowed_hosts", Kind: String, Default: "", Env: "ICHAVA_ALLOWED_HOSTS",
		Pattern: regexp.MustCompile(`^[A-Za-z0-9.,\s-]*$`),
		Help:    "extra upstream hosts, comma separated, on top of the built-in github.com, api.github.com, codeload.github.com, registry.npmjs.org and unicode.org (https only)"},
	{Name: "workspace", Kind: String, Default: "", Env: "ICHAVA_WORKSPACE",
		Help: "directory holding the pack checkouts: a relative pack_root is resolved against it, and it replaces the /work/<pack> a shipped config names (default: /work if present, else the checkouts beside this repository)"},
	{Name: "npm_path", Kind: String, Default: "", Env: "ICHAVA_NPM_PATH",
		Help: "the npm executable, for the npm pack fallback when the registry fetch fails (default: PATH, then Homebrew, Volta, fnm, asdf and nvm's directories; npm's own on Windows)"},
	{Name: "packages_dirs", Kind: List, Default: []string{}, Env: "ICHAVA_PACKAGES_DIRS", Aliases: []string{"packages_dir"}, Paths: true,
		Help: "directories holding the ichava pack checkouts, searched in order for <pack>/ (a string or a list; ~ and paths relative to the config file are resolved; ICHAVA_PACKAGES_DIRS uses the OS list separator; --packages-dir repeats). Searched before workspace"},
	{Name: "history_keep", Kind: Int, Default: 50, Env: "ICHAVA_HISTORY_KEEP", Min: 0,
		Help: "copies of each config file kept in ~/.local/state/icon-sets-sync/history/ before a save from the web UI or config edit, fix or restore; 0 keeps none"},
	{Name: "page_size", Kind: Int, Default: 25, Env: "ICHAVA_PAGE_SIZE", Min: 5, Max: 500,
		Help: "rows per page in the web UI's lists (packs, runs, audit results, a run's log); 5 to 500, and a list's own page-size menu overrides it for that view"},
	{Name: "dry_run", Kind: Bool, Default: false, Env: "ICHAVA_DRY_RUN", PackScoped: true,
		Help: "fetch and diff, but write nothing into the pack and 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: "api.enabled", Kind: Bool, Default: false, Env: "ICHAVA_API_ENABLED", Group: GroupIntegrations,
		Help: "serve the REST API under /api/v1 on the serve listener, for bearer tokens made with `api token create`"},
	{Name: "api.allow_remote", Kind: Bool, Default: false, Env: "ICHAVA_API_ALLOW_REMOTE", Group: GroupIntegrations,
		Help: "also serve the API when serve binds beyond loopback (--allow-remote); without it a remote server has no API"},
	{Name: "api.rate_limit", Kind: Int, Default: 60, Env: "ICHAVA_API_RATE_LIMIT", Min: 1, Max: 10000, Group: GroupIntegrations,
		Help: "requests per minute each API token may make; more are answered 429"},
	{Name: "api.tls", Kind: String, Default: TLSAuto, Env: "ICHAVA_API_TLS", Enum: []string{TLSAuto, TLSOffBehindProxy}, Group: GroupIntegrations,
		Help: "auto terminates TLS whenever serve binds beyond loopback (with api.tls_cert and api.tls_key, else a generated self-signed certificate); off-behind-proxy serves plain HTTP there, for a TLS proxy in front"},
	{Name: "api.tls_cert", Kind: String, Default: "", Env: "ICHAVA_API_TLS_CERT", Group: GroupIntegrations,
		Help: "PEM certificate (chain) serve presents beyond loopback; set with api.tls_key"},
	{Name: "api.tls_key", Kind: String, Default: "", Env: "ICHAVA_API_TLS_KEY", Group: GroupIntegrations,
		Help: "PEM private key for api.tls_cert"},
	{Name: "events.stream", Kind: Bool, Default: false, Env: "ICHAVA_EVENTS_STREAM", Group: GroupIntegrations,
		Help: "serve GET /api/v1/events, a Server-Sent Events stream of every event (needs api.enabled)"},
	{Name: "webhooks.enabled", Kind: Bool, Default: false, Env: "ICHAVA_WEBHOOKS_ENABLED", Group: GroupIntegrations,
		Help: "deliver events to webhooks.endpoints while serve runs, signed with each endpoint's secret"},
	{Name: "webhooks.endpoints", Kind: Webhooks, Default: []Webhook{}, Env: "ICHAVA_WEBHOOKS_ENDPOINTS", Group: GroupIntegrations,
		Help: "webhook receivers: a JSON array of {name, url, events, secret_env}; events is required and lists the event types sent. `webhooks add` writes it and makes the secret"},
	{Name: "webhooks.allow_private", Kind: Bool, Default: false, Env: "ICHAVA_WEBHOOKS_ALLOW_PRIVATE", Group: GroupIntegrations,
		Help: "let webhooks reach private, loopback, link-local and other internal addresses (a receiver on the LAN); off refuses them at connect time"},
	{Name: "webhooks.allow_insecure_localhost", Kind: Bool, Default: false, Env: "ICHAVA_WEBHOOKS_ALLOW_INSECURE_LOCALHOST", Group: GroupIntegrations,
		Help: "allow a plain-http webhook URL whose host is localhost, 127.0.0.1 or ::1; every other URL must be https"},
	{Name: "mcp.enabled", Kind: Bool, Default: false, Env: "ICHAVA_MCP_ENABLED", Group: GroupIntegrations,
		Help: "let `icon-sets-sync mcp` serve the Model Context Protocol on stdio (its --enable does the same for one run)"},
	{Name: "mcp.allow_writes", Kind: Bool, Default: false, Env: "ICHAVA_MCP_ALLOW_WRITES", Group: GroupIntegrations,
		Help: "offer the MCP write tools (sync_pack, cancel_job, set_setting); never with --read-only, and a real sync still needs confirm set to the pack's slug"},
}

Keys is the registry, in display order.

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

Functions

func FormatValue added in v0.1.3

func FormatValue(r Resolved, name string) string

FormatValue renders any setting as text, for tables: a list joined with the OS list separator.

func GlobalConfigPath

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

GlobalConfigPath finds the optional global config file.

It is FindGlobalConfig's Path, legacy locations included. Returns "" with no error when there is none: the file is optional, and a fresh machine or a CI runner has none.

func GlobalSchema added in v0.1.3

func GlobalSchema() ([]byte, error)

GlobalSchema is the JSON Schema of the global config, generated from Keys so the two cannot drift: config/schema/global.schema.json is its output, and a test fails when the file is stale.

func LegacyConfigDirs added in v0.1.3

func LegacyConfigDirs() []string

LegacyConfigDirs are the old homes of the global config: the OS config directory, when it differs from ~/.config. Nil when there is none.

func Names

func Names() []string

Names returns every key name, sorted.

func ResolvePaths added in v0.1.3

func ResolvePaths(v Values, base string)

ResolvePaths expands ~ and makes relative entries of every Paths key in v absolute against base (a config file's directory, or the working directory). It is applied where a layer is read, because only there is it known what a relative path was relative to.

Types

type Emoji

type Emoji struct {
	UnicodeVersion 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 GlobalLocation added in v0.1.3

type GlobalLocation struct {
	// Path is the file read, or "" when there is none.
	Path string
	// Default is where a global config belongs on this machine:
	// $XDG_CONFIG_HOME/icon-sets-sync/config.json, else
	// ~/.config/icon-sets-sync/config.json -- on every OS, Windows included.
	Default string
	// Layer names what chose Path: ICHAVA_GLOBAL_CONFIG, XDG_CONFIG_HOME,
	// "~/.config" or "legacy location".
	Layer string
	// Legacy is set when Path is at an old location (the OS config directory,
	// %AppData% or ~/Library/Application Support) because the default has no
	// file. It is read, never moved; `config migrate` copies it.
	Legacy bool
}

GlobalLocation is where the global config was found, and where it belongs.

func FindGlobalConfig added in v0.1.3

func FindGlobalConfig(lookup func(string) (string, bool), legacyDirs []string) (GlobalLocation, error)

FindGlobalConfig locates the optional global config. legacyDirs are the old config homes searched, after the default, for a file not yet migrated.

The default deliberately overrides the org rule of %AppData% on Windows (the owner, 2026-11-09): one documented path on every OS.

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.
	Env 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, and
	// Max, when above zero, bounds it from above.
	Enum []string
	Min  int
	Max  int

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

	// Aliases are other names a config file, --set or Lookup accept for this
	// key, such as the singular packages_dir. Values are stored under Name.
	Aliases []string

	// Paths marks a List of directories: ~ is expanded, and a relative entry
	// resolves against the config file that names it (else the working
	// directory).
	Paths bool

	// Group is the section of the Settings page a key is shown in: empty for
	// the main list, GroupIntegrations for the API, events, webhooks and MCP.
	Group string

	Help string
}

Key describes one setting.

func Lookup

func Lookup(name string) (Key, bool)

Lookup returns the key with this name.

func (Key) Check added in v0.1.3

func (k Key) Check(value any) (any, error)

Check validates a decoded value against the key's kind and constraints and returns it as the loader would store it, as Values.Set does.

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
	// List is a list of strings, written as a string or an array in a config
	// file and with the OS list separator (: or ;) in the environment.
	List
	// Webhooks is a list of webhook endpoints: an array of objects in a
	// config file, and the same array as JSON in the environment.
	Webhooks
)

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) Strings added in v0.1.3

func (r Resolved) Strings(name string) []string

Strings returns a list setting.

func (Resolved) Tree

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

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

func (Resolved) Webhooks added in v0.1.3

func (r Resolved) Webhooks(name string) []Webhook

Webhooks returns a webhook endpoints setting.

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.

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.

type Webhook added in v0.1.3

type Webhook struct {
	Name      string   `json:"name"`
	URL       string   `json:"url"`
	Events    []string `json:"events"`
	SecretEnv string   `json:"secret_env,omitempty"`
}

Webhook is one webhook endpoint, as webhooks.endpoints holds it. Its secret is never here: the tool keeps it in the state directory, or SecretEnv names the environment variable holding it.

func FindWebhook added in v0.1.3

func FindWebhook(list []Webhook, name string) (Webhook, error)

FindWebhook returns the endpoint with this name.

Jump to

Keyboard shortcuts

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