LoadPadToml finds and reads the nearest .pad.toml by walking up from cwd. Returns nil if no .pad.toml is found (not an error).
()
| 87 | // LoadPadToml finds and reads the nearest .pad.toml by walking up from cwd. |
| 88 | // Returns nil if no .pad.toml is found (not an error). |
| 89 | func LoadPadToml() (*PadToml, error) { |
| 90 | cwd, err := os.Getwd() |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | |
| 95 | dir := cwd |
| 96 | for { |
| 97 | configPath := filepath.Join(dir, ".pad.toml") |
| 98 | if _, err := os.Stat(configPath); err == nil { |
| 99 | var cfg PadToml |
| 100 | if _, err := toml.DecodeFile(configPath, &cfg); err != nil { |
| 101 | return nil, fmt.Errorf("parse %s: %w", configPath, err) |
| 102 | } |
| 103 | return &cfg, nil |
| 104 | } |
| 105 | |
| 106 | parent := filepath.Dir(dir) |
| 107 | if parent == dir { |
| 108 | break |
| 109 | } |
| 110 | dir = parent |
| 111 | } |
| 112 | |
| 113 | return nil, nil |
| 114 | } |
| 115 | |
| 116 | // WriteWorkspaceLink writes a .pad.toml in the given directory. |
| 117 | // |
no test coverage detected