Documentation
¶
Index ¶
- func FindGitRoot(ctx context.Context, start string) string
- type Project
- func (p *Project) CacheRoot(ctx context.Context) (string, error)
- func (p *Project) ConfigRoot(ctx context.Context) (string, error)
- func (p *Project) DataRoot(ctx context.Context) (string, error)
- func (p *Project) LocalConfigRoot(ctx context.Context) (string, error)
- func (p *Project) StateRoot(ctx context.Context) (string, error)
- type ProjectOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindGitRoot ¶
findGitRoot attempts to use the git CLI to determine the repository top-level directory starting from 'start'. If that fails (git not available, not a git worktree, or command error), it falls back to the original upward filesystem search for a .git entry.
Types ¶
type Project ¶
type Project struct {
Appname string
// Root is the path to the root of the project.
Root string
// contains filtered or unexported fields
}
Project holds paths and configuration roots for a repository-backed project. Root is the repository root. Other roots default to platform user-scoped locations when not provided.
func NewProject ¶
NewProject constructs a Project and fills missing roots using platform defaults derived from the provided context.
Behavior:
- If an option sets a value it is used as-is.
- If Root is not set it is inferred from Env.Getwd().
- ConfigRoot, DataRoot, StateRoot and CacheRoot use the corresponding user-scoped platform paths and are joined with DefaultAppName.
func (*Project) CacheRoot ¶
CacheRoot returns the configured cache root or a platform default joined with the Project Appname.
func (*Project) ConfigRoot ¶
ConfigRoot returns the configured config root. When not set it derives a sensible default using the provided context and the Project Appname.
func (*Project) DataRoot ¶
DataRoot returns the configured data root or a platform default joined with the Project Appname.
func (*Project) LocalConfigRoot ¶
LocalConfigRoot returns the repo-local config root. When not explicitly set it defaults to "<Root>/.<appname>".
type ProjectOption ¶
func WithAutoRootDetect ¶
func WithAutoRootDetect() ProjectOption
WithAutoRootDetect returns an option that sets Root by detecting the repository top-level directory using the Env from the provided context. If detection fails the option leaves Root unchanged.
func WithCacheRoot ¶
func WithCacheRoot(path string) ProjectOption
WithCacheRoot sets the cache root path on the Project.
func WithConfigRoot ¶
func WithConfigRoot(path string) ProjectOption
WithConfigRoot sets the config root path on the Project.
func WithDataRoot ¶
func WithDataRoot(path string) ProjectOption
WithDataRoot sets the data root path on the Project.
func WithRoot ¶
func WithRoot(path string) ProjectOption
WithRoot sets the repository root on the Project.
func WithStateRoot ¶
func WithStateRoot(path string) ProjectOption
WithStateRoot sets the state root path on the Project.