settings

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 12 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 manages grat's user-local configuration and scan roots.

Index

Constants

View Source
const (
	// CurrentVersion is the supported settings schema version.
	CurrentVersion = 1
	// FileName is the persistent settings filename below ConfigDirectory.
	FileName = "settings.toml"
)
View Source
const ProjectsDirectoryName = "projects"

ProjectsDirectoryName is the directory below grat's own configuration directory that holds a configuration for a project which has no file of its own.

Variables

This section is empty.

Functions

func CanonicalProjectRoot

func CanonicalProjectRoot(root string) (string, error)

CanonicalProjectRoot reduces the spellings of one directory to a single key.

A path reached through a symlink and the path it resolves to name the same project, and hashing them separately would give it two configurations, one of which nothing would ever read. Where the directory is gone the links cannot be resolved and the cleaned path is used instead: an entry was canonical when it was written, so that is what still matches it for removal.

func ConfigDirectory

func ConfigDirectory() (string, error)

ConfigDirectory returns grat's platform-specific user configuration directory.

func Contains

func Contains(root string, candidate string) (bool, error)

Contains reports whether candidate resolves to root or one of its descendants.

func MissingHeld

func MissingHeld(projects []HeldProject) []string

MissingHeld reports the held configurations whose project directory is no longer on this machine.

A path is the key, and a project that moves therefore leaves its configuration behind rather than taking it along. That is reported rather than cleaned up on sight, for the reason Missing gives about scan directories: a directory somebody moved is an ordinary thing to happen, and the command that would remove the entry has to keep working.

Types

type HeldProblem

type HeldProblem struct {
	// Path is the file that could not be used.
	Path string
	// Err says why.
	Err error
}

HeldProblem records a held configuration that could not be read, so one broken entry does not hide the rest.

type HeldProject

type HeldProject struct {
	// Root is the project directory the configuration belongs to.
	Root string
	// Config is what a grat.config in that directory would have held.
	Config config.Config
}

HeldProject is one configuration grat keeps on behalf of a project that carries no grat.config.

type Settings

type Settings struct {
	Version     int      `toml:"version"`
	Directories []string `toml:"directories"`

	// InstalledTailscale records that grat put Tailscale on this machine, so
	// that uninstall knows it may take it away again.
	//
	// It cannot be worked out afterwards: a Tailscale that grat installed and one
	// somebody installed themselves look identical on disk. Without this, an
	// uninstall would either leave it behind or remove something it never put
	// there, and the second is the one that cannot be undone.
	InstalledTailscale bool `toml:"installed_tailscale,omitempty"`
}

Settings is the declarative user-local configuration for grat.

func (Settings) Missing

func (settings Settings) Missing() []string

Missing reports the registered directories that are no longer on this machine.

Whether one exists is deliberately not part of validate. A directory somebody deleted is an ordinary thing to happen and says nothing about the other entries, whilst treating it as a broken file made every command fail, including the one that removes it. So it is reported here and skipped by whatever walks it, rather than refusing to read the settings at all.

type Store

type Store struct {
	ConfigDir func() (string, error)
	HomeDir   func() (string, error)
	Getwd     func() (string, error)
	Rename    func(string, string) error
}

Store provides filesystem seams for settings operations. Zero-valued hooks use the operating system implementations.

func (Store) Add

func (store Store) Add(path string, cwd string) (Settings, error)

Add normalizes path, persists it once, and returns the complete settings.

func (Store) DefaultDirectory

func (store Store) DefaultDirectory(cwd string) (string, error)

DefaultDirectory returns an existing ~/Sites when available, otherwise cwd.

func (Store) HeldProject

func (store Store) HeldProject(root string) (config.Config, bool, error)

HeldProject returns the configuration held for root, and whether one exists.

func (Store) HeldProjects

func (store Store) HeldProjects() ([]HeldProject, []HeldProblem, error)

HeldProjects returns every configuration grat holds, sorted by project directory, together with the entries that could not be read.

func (Store) HoldProject

func (store Store) HoldProject(root string, value config.Config) error

HoldProject stores value as the configuration for root.

It replaces whatever was held for that directory, which is what makes a second discover run behave the same as it does for a file.

func (Store) Load

func (store Store) Load() (settings Settings, exists bool, result error)

Load reads and validates settings. exists is false when no settings file has been created yet.

func (Store) Normalize

func (store Store) Normalize(path string, cwd string) (string, error)

Normalize expands a leading home marker and returns an existing canonical directory. Relative paths are evaluated from cwd.

func (Store) Path

func (store Store) Path() (string, error)

Path returns the complete path to settings.toml without creating it.

func (Store) ProjectsDirectory

func (store Store) ProjectsDirectory() (string, error)

ProjectsDirectory returns the directory holding registry-kept configurations, without creating it.

func (Store) ReleaseProject

func (store Store) ReleaseProject(root string) (bool, error)

ReleaseProject removes the configuration held for root. released is false where nothing was held for it.

func (Store) Remove

func (store Store) Remove(path string, cwd string) (settings Settings, removed bool, result error)

Remove normalizes path, removes a matching root when present, and persists the remaining settings. removed is false for an unconfigured root.

func (Store) Save

func (store Store) Save(settings Settings) error

Save validates and atomically replaces settings.toml.

Jump to

Keyboard shortcuts

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