Documentation
¶
Overview ¶
Package config loads gu's user configuration and resolves settings that have more than one possible source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
func Dir() string
Dir returns the configuration directory, honouring XDG.
It answers with the old directory when that is the one that exists, so an upgrade does not silently start ignoring the config and the stacks someone already had. Nothing is migrated behind their back: rename it when you like, and gu will use the new one from then on.
func ResolveReadOnly ¶
func ResolveReadOnly(flag bool, p ProfileConfig, cfg Config) bool
ResolveReadOnly applies the documented precedence for read-only mode: --read-only flag > per-profile setting > global setting > writable.
Read-only is deliberately launch-time only; there is no runtime unlock, because a mode you can toggle by accident is not a safety feature.
Types ¶
type Config ¶
type Config struct {
DefaultProfile string `mapstructure:"default_profile"`
ReadOnly bool `mapstructure:"read_only"`
// Icons selects the glyph set: "nerd" (the default, needing a patched
// font), "geometric", or "ascii".
Icons string `mapstructure:"icons"`
// AutoRefresh re-fetches the open screen on a timer, and RefreshInterval
// is how often. They are two settings rather than one duration because
// turning the behaviour off and choosing its cadence are different
// decisions: switching it off should not mean forgetting the number you
// liked.
AutoRefresh bool `mapstructure:"auto_refresh"`
RefreshInterval time.Duration `mapstructure:"refresh_interval"`
// ListRefreshInterval is the cadence for listings, which go stale far more
// slowly than a running pipeline does. One number for both meant either a
// pipeline you had to keep reloading by hand or a work list re-fetching
// half a dozen endpoints every few seconds; they are different questions
// and now have different answers.
ListRefreshInterval time.Duration `mapstructure:"list_refresh_interval"`
// Cache keeps provider responses on disk so a screen you have seen before
// is drawn from the last answer while a fresh one is fetched. It holds
// responses only — never a credential.
Cache bool `mapstructure:"cache"`
// CacheMaxAge bounds how old a cached answer may be and still be drawn
// before the fresh one arrives. Past it the entry is still used to
// revalidate, which costs a round trip but no body.
CacheMaxAge time.Duration `mapstructure:"cache_max_age"`
Profiles map[string]ProfileConfig `mapstructure:"profiles"`
}
Config is the whole of ~/.config/gu/config.yaml.
func Load ¶
Load reads config.yaml from dir. A missing file is not an error: it yields a fully defaulted Config so gu works with no configuration at all.
func (Config) CacheEvery ¶
CacheEvery is how long a cached answer may be shown before it is refetched rather than merely revalidated, and zero when caching is off.
func (Config) ListRefreshEvery ¶
ListRefreshEvery is how often a listing should refresh itself, and zero when it should not. It falls back to the general interval when unset, so a config that only ever knew about one number keeps behaving as it reads.
func (Config) RefreshEvery ¶
RefreshEvery is how often the UI should refresh itself, and zero when it should not.
A non-positive interval disables it as surely as auto_refresh: false does — a refresh every zero seconds is not a cadence, and the caller should not have to defend against one.
type ProfileConfig ¶
type ProfileConfig struct {
Name string `mapstructure:"-"`
Root string `mapstructure:"root"`
GlabConfigDir string `mapstructure:"glab_config_dir"`
GhConfigDir string `mapstructure:"gh_config_dir"`
// ReadOnly is a pointer so "unset" is distinguishable from "false",
// which ResolveReadOnly needs in order to fall through to the global.
ReadOnly *bool `mapstructure:"read_only"`
}
ProfileConfig describes one account identity. A profile is defined by its CLI configuration directories, never by hostname: two profiles routinely share a host (both real accounts live on gitlab.com).