Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotRegistered = errors.New("no workspace registered for path")
Functions ¶
This section is empty.
Types ¶
type Info ¶ added in v0.2.1
Info is a presentation-ready registry entry: the path key joined with the stored fields. Returned by List.
type Workspaces ¶
type Workspaces struct {
// contains filtered or unexported fields
}
func New ¶
func New(baseDir string) *Workspaces
func (*Workspaces) Init ¶
func (w *Workspaces) Init(pwd string) (string, error)
Init registers pwd (absolute, EvalSymlinks-evaluated); registering an already-known pwd or ancestor is a no-op. The Load→mutate→Save sequence runs under config.WithLock so concurrent Init calls for distinct paths don't lose updates.
func (*Workspaces) List ¶ added in v0.2.1
func (w *Workspaces) List(s *config.Settings) []Info
List returns every registered workspace sorted by name. A nil settings yields an empty slice. The path-keyed layout of s.Workspaces stays encapsulated here so callers never iterate the registry map directly.
func (*Workspaces) Lookup ¶
func (w *Workspaces) Lookup(s *config.Settings, pwd string) (matchedRoot, cacheDir string, err error)
Lookup returns the registered ancestor root (mount this, not pwd) and its cache directory. pwd must be absolute and EvalSymlinks-evaluated. The caller must supply a previously-loaded *config.Settings; Lookup does not load settings itself, which lets callers load once and pass the result to both Lookup and any subsequent settings-dependent logic. A nil settings is treated as an empty settings (no workspaces registered).
func (*Workspaces) Remove ¶ added in v0.2.1
func (w *Workspaces) Remove(name string) (cacheDir string, err error)
Remove unregisters the workspace identified by name from the settings file and returns the cache directory path so the caller can delete it after the lock is released. The entire Load→mutate→Save sequence runs under config.WithLock (mirroring Init) so concurrent Remove calls are safe.
config.WithLock is used instead of config.Update because:
- the not-found path must return ErrNotRegistered without calling Save;
- the success path must surface cacheDir, a value computed inside the lock.
The reused ErrNotRegistered sentinel's path-flavoured wording ("no workspace registered for path") is intentionally never surfaced — the CLI layer matches it with errors.Is and prints its own message.
The lock does not touch the filesystem: after Remove returns the caller owns os.RemoveAll(cacheDir). Settings are mutated first (under the short lock) so that if RemoveAll fails the entry is already gone and cannot be re-removed.