From 97f514ccce2137788b74bf4eef833b72a5c17cf8 Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Fri, 4 Apr 2025 19:44:55 +0200 Subject: [PATCH] feat(CA): create author function (required for gh command) --- src/cmd/utils/author_file_utils.go | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/cmd/utils/author_file_utils.go b/src/cmd/utils/author_file_utils.go index bb1c6c4..0cc4d8a 100644 --- a/src/cmd/utils/author_file_utils.go +++ b/src/cmd/utils/author_file_utils.go @@ -73,6 +73,38 @@ func CheckAuthorFile() string { return authorfile } +func CreateAuthor(user User) { + Users[user.Shortname] = user + Users[user.Longname] = user + + // Specifically for the json file + Authors.Authors[user.Longname] = user + + data, err := json.MarshalIndent(Authors, "", " ") + if err != nil { + panic(fmt.Sprintf("Error marshalling json: %v", err)) + + } + + // open author_file + author_file := Find_authorfile() + f, err := os.OpenFile(author_file, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + panic(err) + } + + defer f.Close() + + // write the data to the file + f.Truncate(0) + f.Seek(0, 0) + f.Write(data) + f.Close() + + // redefine the users map for the tui to use + Define_users(Find_authorfile()) +} + func DeleteOneAuthor(author string) { author_file := Find_authorfile()