LoadPadToml finds and reads the nearest .pad.toml by walking up from cwd. Returns nil if no .pad.toml is found (not an error).
()
| 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). |
| 60 | func LoadPadToml() (*PadToml, error) { |
| 61 | cwd, err := os.Getwd() |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | dir := cwd |
| 67 | for { |
| 68 | configPath := filepath.Join(dir, ".pad.toml") |
| 69 | if _, err := os.Stat(configPath); err == nil { |
| 70 | var cfg PadToml |
| 71 | if _, err := toml.DecodeFile(configPath, &cfg); err != nil { |
| 72 | return nil, fmt.Errorf("parse %s: %w", configPath, err) |
| 73 | } |
| 74 | return &cfg, nil |
| 75 | } |
| 76 | |
| 77 | parent := filepath.Dir(dir) |
| 78 | if parent == dir { |
| 79 | break |
| 80 | } |
| 81 | dir = parent |
| 82 | } |
| 83 | |
| 84 | return nil, nil |
| 85 | } |
| 86 | |
| 87 | // WriteWorkspaceLink writes a .pad.toml in the given directory. |
| 88 | // |
no test coverage detected