Load returns the parsed config.yaml. When path is empty the canonical location is consulted; when that file is missing the bundled defaults are returned instead so the CLI keeps working on a fresh install.
(path string)
| 55 | // location is consulted; when that file is missing the bundled defaults are |
| 56 | // returned instead so the CLI keeps working on a fresh install. |
| 57 | func Load(path string) (CamConfig, error) { |
| 58 | if path == "" { |
| 59 | path = DefaultPath() |
| 60 | } |
| 61 | data, err := os.ReadFile(path) |
| 62 | if err != nil { |
| 63 | if os.IsNotExist(err) { |
| 64 | return Bundled() |
| 65 | } |
| 66 | return CamConfig{}, fmt.Errorf("camconfig: read %s: %w", path, err) |
| 67 | } |
| 68 | cfg, parseErr := parse(data) |
| 69 | if parseErr != nil { |
| 70 | return CamConfig{}, fmt.Errorf("camconfig: parse %s: %w", path, parseErr) |
| 71 | } |
| 72 | cfg.Cache.Directory = pathutil.Expand(cfg.Cache.Directory) |
| 73 | return cfg, nil |
| 74 | } |
| 75 | |
| 76 | // Bundled returns the parsed bundled config.yaml shipped with the binary. |
| 77 | // Used as a fallback when no user file is present and exposed so tests can |