Documentation
¶
Overview ¶
Package project manages project directories under a configured root.
Index ¶
- Variables
- type CoderRef
- type Project
- type Repository
- func (r *Repository) Create(rawName string) (string, error)
- func (r *Repository) EnsureRoot() (string, error)
- func (r *Repository) Find(raw string) (Project, error)
- func (r *Repository) FindByName(raw string) (Project, error)
- func (r *Repository) Label(path string) string
- func (r *Repository) List() []Project
- func (r *Repository) ProjectNameFor(cwd string) string
- func (r *Repository) Remove(p Project) error
- func (r *Repository) SelectablePaths() []string
- func (r *Repository) Touch(name string)
- func (r *Repository) ValidatePath(raw string) (string, error)
- type ShellRef
- type TerminalRef
- type WorktreeRef
Constants ¶
This section is empty.
Variables ¶
var ErrExists = errors.New("A project with that name already exists.")
ErrExists is what Create answers for a name whose directory already holds content. It is a sentinel so a caller can tell the taken name apart from a name that cannot be used at all.
Functions ¶
This section is empty.
Types ¶
type CoderRef ¶
type CoderRef struct {
ID string
Name string
Coder string // owning coder id, for the badge when several coders run
At time.Time // started (active) or last updated (inactive); for date sorting
TabPos int // tab strip position from @dc_tab_pos, 0 when unset (active only)
Group string // split view group id from @dc_tab_group, empty when ungrouped
GroupPos int // position inside the group from @dc_tab_gpos, 0 when unset
HasNews bool // an unread notification points at this coder
}
type Project ¶
type Project struct {
Name string
Root string
Path string
Label string
GitBranch string
GitOrigin string
GitOriginURL string
GitRepo bool
GitWorktree bool // .git is a gitdir pointer file of a linked worktree
GitWorktreeOf string // main repository's project name, "" when it is no project under the root
GitWorktreeMain string // main repository's path on disk, the fallback label when GitWorktreeOf is empty
GitWorktrees []WorktreeRef // linked worktrees registered in this repository, empty for a worktree itself
ActiveCoders int
InactiveCoders int
ActiveCoderRefs []CoderRef
InactiveCoderRefs []CoderRef
ShellRefs []ShellRef
ActiveRefs []TerminalRef // coders and shells merged in tab strip order
LastUsedUnix int64 // last time the project was opened; 0 = never
HasNews bool // any coder or shell below has an unread notification
}
Project is one project directory.
type Repository ¶
type Repository struct {
Root string
// contains filtered or unexported fields
}
Repository wraps the on-disk projects root.
func NewRepository ¶
func NewRepository(root string, store *recent.Store) *Repository
NewRepository creates a Repository for the given root directory. The store records and supplies per-project last-used timestamps.
func (*Repository) Create ¶
func (r *Repository) Create(rawName string) (string, error)
Create makes a new project directory under the root. A directory that already exists but is empty is adopted and answered like a fresh one, a leftover of an earlier attempt is a place to fill and not a refusal; anything with content in it, and anything that is not a plain directory, is somebody's data and answers ErrExists.
func (*Repository) EnsureRoot ¶
func (r *Repository) EnsureRoot() (string, error)
EnsureRoot creates the root if missing and returns its resolved path.
func (*Repository) Find ¶
func (r *Repository) Find(raw string) (Project, error)
Find resolves a project from a raw path.
func (*Repository) FindByName ¶
func (r *Repository) FindByName(raw string) (Project, error)
FindByName resolves a project from its directory name under the configured root.
func (*Repository) Label ¶
func (r *Repository) Label(path string) string
Label returns a short user-facing label (path relative to root when possible).
func (*Repository) List ¶
func (r *Repository) List() []Project
List returns all selectable projects as Project records.
func (*Repository) ProjectNameFor ¶
func (r *Repository) ProjectNameFor(cwd string) string
ProjectNameFor returns the name of the top-level project that cwd lives under, or "" when cwd is outside the projects root. Unlike Find it accepts arbitrary subdirectories, so a session or shell working deep inside a project still maps back to it. It is cheap: it only inspects the path and reads no git metadata, so it is safe to call per entry in list/quick-nav views.
func (*Repository) Remove ¶
func (r *Repository) Remove(p Project) error
Remove deletes a project directory. The caller is responsible for checking session conflicts first. A project that is a linked worktree takes its registration in the main repository with it, what a later `git worktree prune` would do; without that the main keeps the worktree's branch checked out and refuses it.
func (*Repository) SelectablePaths ¶
func (r *Repository) SelectablePaths() []string
SelectablePaths returns absolute project directory paths suitable as session working directories.
func (*Repository) Touch ¶
func (r *Repository) Touch(name string)
Touch records that the named project was just opened.
func (*Repository) ValidatePath ¶
func (r *Repository) ValidatePath(raw string) (string, error)
ValidatePath checks that raw is a non-symlink project directly under the root.
type ShellRef ¶
type ShellRef struct {
ID string
Name string
At time.Time // started; tiebreak for the tab order sort
TabPos int // tab strip position from @dc_tab_pos, 0 when unset
Group string // split view group id from @dc_tab_group, empty when ungrouped
GroupPos int // position inside the group from @dc_tab_gpos, 0 when unset
HasNews bool // an unread notification points at this shell
}
type TerminalRef ¶
type TerminalRef struct {
ID string
Name string
Kind string // "coder" or "shell"
Coder string // owning coder id when Kind is "coder"
HasNews bool
}
TerminalRef is one live coder or shell of a project, merged into the tab strip order for the projects page chip row.
type WorktreeRef ¶ added in v1.59.0
type WorktreeRef struct {
Path string // worktree directory on disk
Project string // its project name, "" when it does not lie directly under the root
}
WorktreeRef is one linked worktree registered in a project's repository.