refactor(json): create author now works on new json authorfile

This commit is contained in:
Slug-Boi
2025-04-02 18:35:10 +02:00
parent 4a8572efdf
commit 5106e9ce1e
+25 -17
View File
@@ -4,6 +4,7 @@ package tui
// from the Bubbles component library. // from the Bubbles component library.
import ( import (
"encoding/json"
"fmt" "fmt"
"os" "os"
"strings" "strings"
@@ -250,28 +251,35 @@ func (m *model_ca) AddAuthor() {
defer f.Close() defer f.Close()
sb := strings.Builder{} // create and add the user to the users map
sb.WriteRune('\n') usr := utils.User{
Shortname: m.inputs[0].Value(),
sb.WriteString(fmt.Sprintf("%s|%s|%s|%s", Longname: m.inputs[1].Value(),
m.inputs[0].Value(), Username: m.inputs[2].Value(),
m.inputs[1].Value(), Email: m.inputs[3].Value(),
m.inputs[2].Value(), Ex: m.exclude,
m.inputs[3].Value())) Groups: strings.Split(m.inputs[4].Value(), "|"),
if m.exclude {
sb.WriteString(fmt.Sprintf("|%s", "ex"))
} }
if m.inputs[4].Value() != "" { utils.Users[m.inputs[0].Value()] = usr
sb.WriteString(fmt.Sprintf(";;%s", m.inputs[4].Value())) utils.Users[m.inputs[1].Value()] = usr
utils.Authors.Authors[m.inputs[1].Value()] = usr
data, err := json.MarshalIndent(utils.Authors, "", " ")
if err != nil {
panic(fmt.Sprintf("Error marshalling json: %v", err))
} }
//sb.WriteRune('\n') // write the data to the file
f.Truncate(0)
f.Seek(0, 0)
f.Write(data)
f.Close()
if _, err = f.WriteString(sb.String()); err != nil { // redefine the users map for the tui to use
panic(err)
}
utils.Define_users(utils.Find_authorfile()) utils.Define_users(utils.Find_authorfile())
author := m.inputs[0].Value() author := m.inputs[0].Value()