MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / BuildWorkspaceContext

Function BuildWorkspaceContext

internal/cli/workspace_context_detect.go:15–49  ·  view source on GitHub ↗

BuildWorkspaceContext converts detected project metadata plus the current Pad client configuration into a machine-readable workspace context.

(dir string, info ProjectInfo, cfg *config.Config)

Source from the content-addressed store, hash-verified

13// BuildWorkspaceContext converts detected project metadata plus the current Pad
14// client configuration into a machine-readable workspace context.
15func BuildWorkspaceContext(dir string, info ProjectInfo, cfg *config.Config) *models.WorkspaceContext {
16 context := &models.WorkspaceContext{
17 Repositories: detectWorkspaceRepositories(dir),
18 Paths: detectWorkspacePaths(dir),
19 Commands: detectWorkspaceCommands(info),
20 Stack: &models.WorkspaceStack{
21 Languages: uniqueNonEmpty([]string{info.Language}),
22 Frameworks: uniqueNonEmpty(info.Frameworks),
23 PackageManagers: uniqueNonEmpty(info.PackageManagers),
24 },
25 Deployment: detectWorkspaceDeployment(cfg),
26 Assumptions: detectWorkspaceAssumptions(dir, cfg),
27 }
28
29 if len(context.Repositories) == 0 {
30 context.Repositories = nil
31 }
32 if context.Paths != nil && *context.Paths == (models.WorkspacePaths{}) {
33 context.Paths = nil
34 }
35 if context.Commands != nil && *context.Commands == (models.WorkspaceCommands{}) {
36 context.Commands = nil
37 }
38 if context.Stack != nil && len(context.Stack.Languages) == 0 && len(context.Stack.Frameworks) == 0 && len(context.Stack.PackageManagers) == 0 {
39 context.Stack = nil
40 }
41 if context.Deployment != nil && *context.Deployment == (models.WorkspaceDeployment{}) {
42 context.Deployment = nil
43 }
44 if len(context.Assumptions) == 0 {
45 context.Assumptions = nil
46 }
47
48 return context
49}
50
51func detectWorkspaceRepositories(dir string) []models.WorkspaceRepository {
52 var repos []models.WorkspaceRepository

Callers 1

Calls 6

detectWorkspacePathsFunction · 0.85
detectWorkspaceCommandsFunction · 0.85
uniqueNonEmptyFunction · 0.85

Tested by 1