MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SaveKeywords

Function SaveKeywords

internal/keywords/admin.go:60–86  ·  view source on GitHub ↗
(a *Aliases)

Source from the content-addressed store, hash-verified

58}
59
60func 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.

Callers 1

apiV1PatchKeywordsFunction · 0.92

Calls 6

GetFilePathsConfigFunction · 0.92
WriteFileFunction · 0.92
extractSectionCommentsFunction · 0.85
insertSectionCommentsFunction · 0.85
StringMethod · 0.65
ValidateMethod · 0.65

Tested by

no test coverage detected