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¶
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¶
Max Depth¶
Default: 100 levels. Override to limit scanning:
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.