refactor: panic and rename variable plus move an error so it can actually trigger

This commit is contained in:
Slug-Boi
2025-04-09 21:00:30 +02:00
parent 3db2ca2566
commit 33d93c834d
+9 -10
View File
@@ -13,12 +13,11 @@ import (
// An example of the author file can be found in the examples folder of the repo // An example of the author file can be found in the examples folder of the repo
func Find_authorfile() string { func Find_authorfile() string {
if os.Getenv("author_file") == "" { if os.Getenv("author_file") == "" {
authors, err := os.UserConfigDir() dirs, err := os.UserConfigDir()
if err != nil { if err != nil {
fmt.Println("Error getting user config directory") panic(fmt.Sprintf("Error getting user config directory: %v", err))
os.Exit(2)
} }
return (authors + "/cocommit/authors.json") return (dirs + "/cocommit/authors.json")
} else { } else {
return os.Getenv("author_file") return os.Getenv("author_file")
} }
@@ -106,6 +105,12 @@ func CreateAuthor(user User) {
} }
func DeleteOneAuthor(author string) { func DeleteOneAuthor(author string) {
// check that users aren't empty
if len(Users) < 1 {
fmt.Println("No users to remove")
return
}
author_file := Find_authorfile() author_file := Find_authorfile()
if _, exists := Users[author]; !exists { if _, exists := Users[author]; !exists {
@@ -121,12 +126,6 @@ func DeleteOneAuthor(author string) {
} }
defer file.Close() defer file.Close()
// check that users aren't empty
if len(Users) < 1 {
fmt.Println("No users to remove")
return
}
usr := Users[author] usr := Users[author]
// Remove the user from the Author struct (try both short and long name) // Remove the user from the Author struct (try both short and long name)