project

package
v3.16.10 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProjectOptions = [...]ProjectOption{
	WithFindRepoUpward(),
	WithRespectGitignore(true),
	WithEnvFilesReadOrder([]string{".env"}),
	WithIgnoreFilePatterns("node_modules", ".venv", "vendor"),
}
View Source
var ErrReturnEarly = errors.New("return early")

Functions

func ExtractDataFromLoadEvent

func ExtractDataFromLoadEvent[T any](event LoadEvent) T

func FormatFiles

func FormatFiles(files []string, options *FormatOptions) error

func GetRelativePath

func GetRelativePath(cwd, path string) string

func LoadFiles

func LoadFiles(ctx context.Context, p *Project) ([]string, error)

LoadFiles returns a list of file names found in the project.

func SortByProximity

func SortByProximity(tasks []Task, cwd string)

SortByProximity sorts tasks by promximity to the cwd

Types

type Filter

type Filter func(Task) (bool, error)

type FormatOptions

type FormatOptions struct {
	IdentityResolver *identity.IdentityResolver
	FormatJSON       bool
	Write            bool
	Outputter        FuncOutput
	Reset            bool
}

type FuncOutput

type FuncOutput func(string, []byte) error

type LoadEvent

type LoadEvent struct {
	Type LoadEventType
	Data any
}

type LoadEventErrorData

type LoadEventErrorData struct {
	Err error
}

type LoadEventFinishedParsingDocumentData

type LoadEventFinishedParsingDocumentData struct {
	Path string
}

type LoadEventFinishedWalkData

type LoadEventFinishedWalkData struct{}

type LoadEventFoundDirData

type LoadEventFoundDirData struct {
	Path string
}

type LoadEventFoundFileData

type LoadEventFoundFileData struct {
	Path string
}

type LoadEventFoundTaskData

type LoadEventFoundTaskData struct {
	Task Task
}

type LoadEventStartedParsingDocumentData

type LoadEventStartedParsingDocumentData struct {
	Path string
}

type LoadEventStartedWalkData

type LoadEventStartedWalkData struct{}

type LoadEventType

type LoadEventType uint8
const (
	LoadEventStartedWalk LoadEventType = iota + 1
	LoadEventFoundDir
	LoadEventFoundFile
	LoadEventFinishedWalk
	LoadEventStartedParsingDocument
	LoadEventFinishedParsingDocument
	LoadEventFoundTask
	LoadEventError
)

type LoadOptions

type LoadOptions struct {
	OnlyFiles bool
}

type Matcher

type Matcher interface {
	MatchString(string) bool
}

func CompileRegex

func CompileRegex(query string) (Matcher, error)

type Project

type Project struct {
	// contains filtered or unexported fields
}

func NewDirProject

func NewDirProject(
	dir string,
	opts ...ProjectOption,
) (*Project, error)

func NewFileProject

func NewFileProject(
	path string,
	opts ...ProjectOption,
) (*Project, error)

func (*Project) EnvDirEnvEnabled

func (p *Project) EnvDirEnvEnabled() bool

func (*Project) EnvFilesReadOrder

func (p *Project) EnvFilesReadOrder() []string

func (*Project) Load

func (p *Project) Load(
	ctx context.Context,
	eventc chan<- LoadEvent,
	onlyFiles bool,
)

func (*Project) LoadEnv

func (p *Project) LoadEnv() ([]string, error)

func (*Project) LoadEnvAsMap

func (p *Project) LoadEnvAsMap() (map[string]string, error)

func (*Project) LoadEnvWithSource

func (p *Project) LoadEnvWithSource() (envWithSource map[string]map[string]string, err error)

func (*Project) LoadRawFile

func (p *Project) LoadRawFile(file string) ([]byte, error)

func (*Project) LoadWithOptions

func (p *Project) LoadWithOptions(
	ctx context.Context,
	eventc chan<- LoadEvent,
	options LoadOptions,
)

func (*Project) Root

func (p *Project) Root() string

type ProjectOption

type ProjectOption func(*Project)

func WithEnvDirEnv

func WithEnvDirEnv(value bool) ProjectOption

func WithEnvFilesReadOrder

func WithEnvFilesReadOrder(order []string) ProjectOption

func WithFindRepoUpward

func WithFindRepoUpward() ProjectOption

func WithIgnoreFilePatterns

func WithIgnoreFilePatterns(patterns ...string) ProjectOption

func WithLogger

func WithLogger(logger *zap.Logger) ProjectOption

func WithRespectGitignore

func WithRespectGitignore(value bool) ProjectOption

type Task

type Task struct {
	CodeBlock       *document.CodeBlock `json:"code_block"`
	DocumentPath    string              `json:"document_path"`
	RelDocumentPath string              `json:"rel_document_path"`
}

Task is struct representing a document.CodeBlock within the context of a project. Instance of document.Document can be retrieved from Task's code block. Task contains absolute and relative path to the document.

func FilterTasksByExactTaskName

func FilterTasksByExactTaskName(tasks []Task, name string) (result []Task, err error)

func FilterTasksByFilename

func FilterTasksByFilename(tasks []Task, expr string) (result []Task, err error)

func FilterTasksByFn

func FilterTasksByFn(tasks []Task, fns ...Filter) (result []Task, err error)

func FilterTasksByID

func FilterTasksByID(tasks []Task, expr string) (result []Task, err error)

func LoadTasks

func LoadTasks(ctx context.Context, p *Project) ([]Task, error)

func (Task) BlockInterpreter

func (t Task) BlockInterpreter() string

BlockInterpreter returns the interpreter specified in the code block attributes, or an empty string if not set.

func (Task) CustomShell

func (t Task) CustomShell(baseShell string) (string, error)

CustomShell returns the shell to use for this task, prioritizing frontmatter shell, then block interpreter, then the provided baseShell.

func (Task) FrontmatterShell

func (t Task) FrontmatterShell() (string, error)

FrontmatterShell returns the shell specified in the document frontmatter, or an error if the frontmatter is invalid or missing.

func (Task) ID

func (t Task) ID() string

Directories

Path Synopsis
testutils provides helpers for integration tests with "internal/project" package.
testutils provides helpers for integration tests with "internal/project" package.

Jump to

Keyboard shortcuts

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