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

Function DetectWorkspace

internal/cli/workspace.go:25–56  ·  view source on GitHub ↗

DetectWorkspace walks up the directory tree from cwd looking for .pad.toml.

(flagOverride string)

Source from the content-addressed store, hash-verified

23
24// DetectWorkspace walks up the directory tree from cwd looking for .pad.toml.
25func DetectWorkspace(flagOverride string) (string, error) {
26 if flagOverride != "" {
27 return flagOverride, nil
28 }
29
30 cwd, err := os.Getwd()
31 if err != nil {
32 return "", err
33 }
34
35 dir := cwd
36 for {
37 configPath := filepath.Join(dir, ".pad.toml")
38 if _, err := os.Stat(configPath); err == nil {
39 var cfg PadToml
40 if _, err := toml.DecodeFile(configPath, &cfg); err != nil {
41 return "", fmt.Errorf("parse %s: %w", configPath, err)
42 }
43 if cfg.Workspace != "" {
44 return cfg.Workspace, nil
45 }
46 }
47
48 parent := filepath.Dir(dir)
49 if parent == dir {
50 break
51 }
52 dir = parent
53 }
54
55 return "", fmt.Errorf("no workspace linked. Run 'pad workspace init' to create one")
56}
57
58// LoadPadToml finds and reads the nearest .pad.toml by walking up from cwd.
59// Returns nil if no .pad.toml is found (not an error).

Callers 10

linkCmdFunction · 0.92
workspacesCmdFunction · 0.92
collectServerInfoFunction · 0.92
completeCollectionNamesFunction · 0.92
ensureWorkspaceFunction · 0.92
openCmdFunction · 0.92
newDynamicResolverFunction · 0.92
recordInstallationFunction · 0.92
getWorkspaceFunction · 0.92

Calls 2

JoinMethod · 0.80
StatMethod · 0.65

Tested by

no test coverage detected