project

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindGitRoot

func FindGitRoot(ctx context.Context, start string) string

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

func NewProject(ctx context.Context, appname string, opts ...ProjectOption) (*Project, error)

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

func (p *Project) CacheRoot(ctx context.Context) (string, error)

CacheRoot returns the configured cache root or a platform default joined with the Project Appname.

func (*Project) ConfigRoot

func (p *Project) ConfigRoot(ctx context.Context) (string, error)

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

func (p *Project) DataRoot(ctx context.Context) (string, error)

DataRoot returns the configured data root or a platform default joined with the Project Appname.

func (*Project) LocalConfigRoot

func (p *Project) LocalConfigRoot(ctx context.Context) (string, error)

LocalConfigRoot returns the repo-local config root. When not explicitly set it defaults to "<Root>/.<appname>".

func (*Project) StateRoot

func (p *Project) StateRoot(ctx context.Context) (string, error)

StateRoot returns the configured state root or a platform default joined with the Project Appname.

type ProjectOption

type ProjectOption = func(ctx context.Context, p *Project)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL