MCPcopy Index your code
hub / github.com/coder/coder / ResolvePath

Function ResolvePath

agent/agentcontextconfig/resolve.go:12–38  ·  view source on GitHub ↗

ResolvePath resolves a single path that may be absolute, home-relative (~/ or ~), or relative to the given base directory. Returns an absolute path. Empty input returns empty.

(raw, baseDir string)

Source from the content-addressed store, hash-verified

10// home-relative (~/ or ~), or relative to the given base
11// directory. Returns an absolute path. Empty input returns empty.
12func ResolvePath(raw, baseDir string) string {
13 raw = strings.TrimSpace(raw)
14 if raw == "" {
15 return ""
16 }
17 switch {
18 case raw == "~":
19 home, err := os.UserHomeDir()
20 if err != nil {
21 return ""
22 }
23 return home
24 case strings.HasPrefix(raw, "~/"):
25 home, err := os.UserHomeDir()
26 if err != nil {
27 return ""
28 }
29 return filepath.Join(home, raw[2:])
30 case filepath.IsAbs(raw):
31 return raw
32 default:
33 if baseDir == "" {
34 return ""
35 }
36 return filepath.Join(baseDir, raw)
37 }
38}
39
40// ResolvePaths splits a comma-separated list of paths and
41// resolves each entry independently. Empty entries and entries

Callers 3

TestResolvePathFunction · 0.92
ResolvePathsFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestResolvePathFunction · 0.74