Add workspace CLI (list/add/remove) and registry hash/unregister

This commit is contained in:
Joshua Bell 2026-01-29 15:18:42 -06:00
parent 2555a47d62
commit 3b4f54984e
3 changed files with 187 additions and 0 deletions

View file

@ -138,3 +138,43 @@ func (r *Registry) Find(hostPath string) mo.Option[Workspace] {
}
return mo.None[Workspace]()
}
// FindByHash looks up a workspace by its hash (or hash prefix)
func (r *Registry) FindByHash(hash string) mo.Option[Workspace] {
for _, ws := range r.workspaces {
if ws.Hash == hash {
return mo.Some(ws)
}
// Also support prefix matching for convenience
if len(hash) >= 3 && len(hash) < 8 && ws.Hash[:len(hash)] == hash {
return mo.Some(ws)
}
}
return mo.None[Workspace]()
}
// Unregister removes a workspace from the registry by host path
func (r *Registry) Unregister(hostPath string) bool {
absPath, err := filepath.Abs(hostPath)
if err != nil {
absPath = hostPath
}
if _, exists := r.workspaces[absPath]; exists {
delete(r.workspaces, absPath)
return true
}
return false
}
// UnregisterByHash removes a workspace from the registry by its hash
func (r *Registry) UnregisterByHash(hash string) mo.Option[Workspace] {
wsOpt := r.FindByHash(hash)
if wsOpt.IsAbsent() {
return mo.None[Workspace]()
}
ws := wsOpt.MustGet()
delete(r.workspaces, ws.HostPath)
return mo.Some(ws)
}