PathFor returns the on-disk path used for read/write at the given scope. The first user path is used for write, even when no file exists yet (the caller's responsibility is to create the directory).
(scope Scope)
| 38 | // The first user path is used for write, even when no file exists yet (the |
| 39 | // caller's responsibility is to create the directory). |
| 40 | func (c *jsonToolConfig) PathFor(scope Scope) string { |
| 41 | switch scope { |
| 42 | case UserScope: |
| 43 | paths := c.UserPaths() |
| 44 | for _, p := range paths { |
| 45 | if pathutil.Exists(p) { |
| 46 | return p |
| 47 | } |
| 48 | } |
| 49 | if len(paths) > 0 { |
| 50 | return paths[0] |
| 51 | } |
| 52 | case ProjectScope: |
| 53 | return c.ProjectPath() |
| 54 | } |
| 55 | return "" |
| 56 | } |
| 57 | |
| 58 | func (c *jsonToolConfig) Load(scope Scope) (map[string]any, string, error) { |
| 59 | path := c.PathFor(scope) |