Documentation
¶
Overview ¶
Package config reads and writes ytrack's configuration directory:
config.yml general preferences hosts.yml per-host metadata and the default host (never secrets)
The directory is $YTRACK_CONFIG_DIR, else $XDG_CONFIG_HOME/ytrack, else %AppData%/ytrack on Windows, else ~/.config/ytrack.
Machine state that is not configuration (the update check) lives in StateDir.
Index ¶
- Constants
- func Dir() (string, error)
- func StateDir() (string, error)
- func ValidatePathGlob(glob string) error
- func WriteFileAtomic(path string, data []byte) error
- type Config
- func (c *Config) AddHostPath(key, glob string) (bool, error)
- func (c *Config) Browser() string
- func (c *Config) CheckUpdate() bool
- func (c *Config) DefaultHost() string
- func (c *Config) Dir() string
- func (c *Config) Host(key string) *HostEntry
- func (c *Config) HostForPath(dirs ...string) (PathMatch, bool)
- func (c *Config) HostKeys() []string
- func (c *Config) HostPaths(key string) []string
- func (c *Config) RemoveHost(key string)
- func (c *Config) RemoveHostPath(key, glob string) bool
- func (c *Config) Save() error
- func (c *Config) SetDefaultHost(key string) error
- func (c *Config) SetHost(key string, entry HostEntry)
- func (c *Config) Timezone() string
- type HostEntry
- type PathMatch
Constants ¶
const ( StorageKeyring = "keyring" StorageFile = "file" )
Storage values record where a host's token lives.
Variables ¶
This section is empty.
Functions ¶
func StateDir ¶ added in v0.2.0
StateDir returns the directory for state ytrack keeps between runs: $XDG_STATE_HOME/ytrack, else %LocalAppData%/ytrack on Windows, else ~/.local/state/ytrack.
func ValidatePathGlob ¶ added in v0.4.0
ValidatePathGlob reports why glob cannot be a host path. A path glob is absolute or starts with ~/, and its only wildcards are * (within one folder name) and ** (any number of folders): /home/me/work/**.
func WriteFileAtomic ¶
WriteFileAtomic writes data to path with mode 0600, creating the parent directory with mode 0700, via a temp file and rename.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the loaded configuration.
func (*Config) AddHostPath ¶ added in v0.4.0
AddHostPath adds glob to the paths of host key, which must be known. It reports whether the glob was new.
func (*Config) CheckUpdate ¶ added in v0.2.0
CheckUpdate reports whether the new-release notice is on (`check_update` in config.yml, default true).
func (*Config) DefaultHost ¶
DefaultHost returns the key of the default host, or "".
func (*Config) HostForPath ¶ added in v0.4.0
HostForPath returns the host whose path glob matches one of dirs. The most specific glob wins: the one with the longest literal text before its first wildcard. A tie goes to the host key that sorts first.
func (*Config) RemoveHost ¶
RemoveHost deletes a host entry. If it was the default, the first remaining host (sorted) becomes the default.
func (*Config) RemoveHostPath ¶ added in v0.4.0
RemoveHostPath removes glob from the paths of host key and reports whether it was there.
func (*Config) SetDefaultHost ¶
SetDefaultHost makes key the default host. The host must be known.
type HostEntry ¶
type HostEntry struct {
URL string `yaml:"url"`
User string `yaml:"user,omitempty"`
Auth string `yaml:"auth,omitempty"`
Storage string `yaml:"storage,omitempty"`
// Paths are folder globs (/abs/dir/**, ~/dir/**) whose commands talk to
// this host when no --host, issue URL or $YTRACK_HOST picks one.
Paths []string `yaml:"paths,omitempty"`
}
HostEntry is the non-secret metadata kept for a logged-in host.