MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / Find

Function Find

internal/envfile/envfile.go:30–56  ·  view source on GitHub ↗

Find returns the first .env file CAM should load. When custom is non-empty and exists, it is returned. When custom is set but missing and strict is true, ErrNotFound is returned. When custom is empty, Find walks the current working directory upward until it locates a .env file or hits a directory

(custom string, strict bool)

Source from the content-addressed store, hash-verified

28// dotenv.find_dotenv behaviour), then falls back to ~/.env and
29// ~/.config/code-agent-manager/.env.
30func Find(custom string, strict bool) (string, error) {
31 if custom != "" {
32 expanded := pathutil.Expand(custom)
33 if pathutil.Exists(expanded) {
34 return expanded, nil
35 }
36 if strict {
37 return "", ErrNotFound
38 }
39 }
40
41 if dir, err := os.Getwd(); err == nil {
42 if found := walkUpward(dir); found != "" {
43 return found, nil
44 }
45 }
46
47 for _, candidate := range []string{
48 filepath.Join(pathutil.Home(), ".env"),
49 filepath.Join(pathutil.ConfigDir(), ".env"),
50 } {
51 if pathutil.Exists(candidate) {
52 return candidate, nil
53 }
54 }
55 return "", ErrNotFound
56}
57
58func walkUpward(start string) string {
59 dir := start

Callers 5

RunMethod · 0.92
TestFindFallsBackToHomeFunction · 0.92

Calls 5

ExpandFunction · 0.92
ExistsFunction · 0.92
HomeFunction · 0.92
ConfigDirFunction · 0.92
walkUpwardFunction · 0.85