LoadGlobalRegistry reads the projects list from ~/.taskmd.yaml (or $TASKMD_HOME_CONFIG). Returns an empty slice and nil error when the file does not exist or contains no projects. Does not validate that project paths exist on disk — callers decide that policy.
()
| 33 | // Returns an empty slice and nil error when the file does not exist or contains no projects. |
| 34 | // Does not validate that project paths exist on disk — callers decide that policy. |
| 35 | func LoadGlobalRegistry() ([]GlobalProjectEntry, error) { |
| 36 | cfgPath, err := globalConfigPath() |
| 37 | if err != nil { |
| 38 | return nil, fmt.Errorf("resolve global config path: %w", err) |
| 39 | } |
| 40 | |
| 41 | data, err := os.ReadFile(cfgPath) |
| 42 | if err != nil { |
| 43 | if os.IsNotExist(err) { |
| 44 | return nil, nil |
| 45 | } |
| 46 | return nil, fmt.Errorf("read global config %s: %w", cfgPath, err) |
| 47 | } |
| 48 | |
| 49 | var cfg globalConfig |
| 50 | if err := yaml.Unmarshal(data, &cfg); err != nil { |
| 51 | return nil, fmt.Errorf("parse global config %s: %w", cfgPath, err) |
| 52 | } |
| 53 | |
| 54 | if len(cfg.Projects) == 0 { |
| 55 | return nil, nil |
| 56 | } |
| 57 | |
| 58 | return parseProjectEntries(cfg.Projects, filepath.Dir(cfgPath)) |
| 59 | } |
| 60 | |
| 61 | // LoadDefaultProject reads the default_project key from the global config. |
| 62 | // Returns empty string if not set or if the config file doesn't exist. |