Skip to content

Workspace

Package: pkg/workspace

Detects project boundaries by walking up from a starting directory to find marker files. Used internally by the generator commands to auto-resolve the project root when running from subdirectories.

Usage

ws, err := workspace.Detect(afero.NewOsFs(), ".", workspace.DefaultMarkers)
if err != nil {
    return errors.Wrap(err, "not inside a project")
}

fmt.Println("Project root:", ws.Root)
fmt.Println("Detected via:", ws.Marker)

From Current Working Directory

ws, err := workspace.DetectFromCWD(afero.NewOsFs(), workspace.DefaultMarkers)

Default Markers

Checked in order โ€” the first match wins:

Marker Detects
.gtb/manifest.yaml GTB-generated project
go.mod Go module root
.git Git repository root

Custom Markers

ws, err := workspace.Detect(fs, startDir, []string{"package.json", "Cargo.toml"})

Max Depth

Default: 100 levels. Override to limit scanning:

ws, err := workspace.Detect(fs, startDir, markers, workspace.WithMaxDepth(10))

Generator Integration

All generator commands (regenerate, generate command/docs/flag, remove) automatically resolve the workspace root when --path is "." (the default). This means you can run gtb regenerate project from any subdirectory within the project.