Documentation
¶
Overview ¶
Package settings manages grat's user-local configuration and scan roots.
Index ¶
- Constants
- func CanonicalProjectRoot(root string) (string, error)
- func ConfigDirectory() (string, error)
- func Contains(root string, candidate string) (bool, error)
- func MissingHeld(projects []HeldProject) []string
- type HeldProblem
- type HeldProject
- type Settings
- type Store
- func (store Store) Add(path string, cwd string) (Settings, error)
- func (store Store) DefaultDirectory(cwd string) (string, error)
- func (store Store) HeldProject(root string) (config.Config, bool, error)
- func (store Store) HeldProjects() ([]HeldProject, []HeldProblem, error)
- func (store Store) HoldProject(root string, value config.Config) error
- func (store Store) Load() (settings Settings, exists bool, result error)
- func (store Store) Normalize(path string, cwd string) (string, error)
- func (store Store) Path() (string, error)
- func (store Store) ProjectsDirectory() (string, error)
- func (store Store) ReleaseProject(root string) (bool, error)
- func (store Store) Remove(path string, cwd string) (settings Settings, removed bool, result error)
- func (store Store) Save(settings Settings) error
Constants ¶
const ( // CurrentVersion is the supported settings schema version. CurrentVersion = 1 // FileName is the persistent settings filename below ConfigDirectory. FileName = "settings.toml" )
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 ¶
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 ¶
ConfigDirectory returns grat's platform-specific user configuration directory.
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 ¶
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) DefaultDirectory ¶
DefaultDirectory returns an existing ~/Sites when available, otherwise cwd.
func (Store) HeldProject ¶
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 ¶
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 ¶
Load reads and validates settings. exists is false when no settings file has been created yet.
func (Store) Normalize ¶
Normalize expands a leading home marker and returns an existing canonical directory. Relative paths are evaluated from cwd.
func (Store) ProjectsDirectory ¶
ProjectsDirectory returns the directory holding registry-kept configurations, without creating it.
func (Store) ReleaseProject ¶
ReleaseProject removes the configuration held for root. released is false where nothing was held for it.