mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
refactor(json): change create authorfile to json file and update directory creator to not panic
This commit is contained in:
@@ -18,7 +18,7 @@ func Find_authorfile() string {
|
|||||||
fmt.Println("Error getting user config directory")
|
fmt.Println("Error getting user config directory")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
return (authors + "/cocommit/authors")
|
return (authors + "/cocommit/authors.json")
|
||||||
} else {
|
} else {
|
||||||
return os.Getenv("author_file")
|
return os.Getenv("author_file")
|
||||||
}
|
}
|
||||||
@@ -40,11 +40,13 @@ func CheckAuthorFile() string {
|
|||||||
cocommit_folder = strings.Join(parts[:len(parts)-1], "/")
|
cocommit_folder = strings.Join(parts[:len(parts)-1], "/")
|
||||||
|
|
||||||
// create the author file
|
// create the author file
|
||||||
|
if os.Stat(cocommit_folder); os.IsNotExist(err) {
|
||||||
err := os.Mkdir(cocommit_folder, 0766)
|
err := os.Mkdir(cocommit_folder, 0766)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error creating directory: ", err, cocommit_folder)
|
fmt.Println("Error creating directory: ", err, cocommit_folder)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
file, err := os.Create(authorfile)
|
file, err := os.Create(authorfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error creating file: ", err)
|
fmt.Println("Error creating file: ", err)
|
||||||
@@ -54,10 +56,15 @@ func CheckAuthorFile() string {
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// write the header to the file
|
// 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'")
|
fmt.Println("Author file created. To add authors please launch the TUI with -a and press 'C'")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user