refactor(json): change create authorfile to json file and update directory creator to not panic

This commit is contained in:
Slug-Boi
2025-04-02 19:27:32 +02:00
parent 375d7f98e5
commit bddcaa9ba2
+10 -3
View File
@@ -18,7 +18,7 @@ func Find_authorfile() string {
fmt.Println("Error getting user config directory")
os.Exit(2)
}
return (authors + "/cocommit/authors")
return (authors + "/cocommit/authors.json")
} else {
return os.Getenv("author_file")
}
@@ -40,11 +40,13 @@ func CheckAuthorFile() string {
cocommit_folder = strings.Join(parts[:len(parts)-1], "/")
// create the author file
if os.Stat(cocommit_folder); os.IsNotExist(err) {
err := os.Mkdir(cocommit_folder, 0766)
if err != nil {
fmt.Println("Error creating directory: ", err, cocommit_folder)
os.Exit(1)
}
}
file, err := os.Create(authorfile)
if err != nil {
fmt.Println("Error creating file: ", err)
@@ -54,10 +56,15 @@ func CheckAuthorFile() string {
defer file.Close()
// write the header to the file
file.WriteString("Syntax: name_short|Name|Username|email (opt: |ex) (opt: ;;group1|group2|group3...)\n")
json_string :=
`{
"Authors": {
}
}`
file.Write([]byte(json_string))
fmt.Println("Author file created. To add authors please launch the TUI with -a and press 'C'")
} else {
os.Exit(1)
}