(a *Aliases)
| 58 | } |
| 59 | |
| 60 | func SaveKeywords(a *Aliases) error { |
| 61 | if a == nil { |
| 62 | return fmt.Errorf("keywords data cannot be nil") |
| 63 | } |
| 64 | |
| 65 | path := configs.GetFilePathsConfig().DataFiles.String() + `/keywords.yaml` |
| 66 | |
| 67 | sectionComments := extractSectionComments(path) |
| 68 | |
| 69 | bytes, err := yaml.Marshal(a) |
| 70 | if err != nil { |
| 71 | return fmt.Errorf("marshaling keywords: %w", err) |
| 72 | } |
| 73 | |
| 74 | bytes = insertSectionComments(bytes, sectionComments) |
| 75 | |
| 76 | if err := util.WriteFile(path, bytes, 0644); err != nil { |
| 77 | return fmt.Errorf("writing keywords file: %w", err) |
| 78 | } |
| 79 | |
| 80 | loadedKeywords = a |
| 81 | if err := loadedKeywords.Validate(); err != nil { |
| 82 | return fmt.Errorf("validating keywords after save: %w", err) |
| 83 | } |
| 84 | |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | // extractSectionComments reads the file at path and returns comment blocks |
| 89 | // (including preceding blank lines) keyed by the top-level YAML key they precede. |
no test coverage detected