refactor: update check author file function and create new flag to enter author list tui mode

This commit is contained in:
Slug-Boi
2024-10-28 19:29:03 +01:00
parent c4ac188918
commit ff9b648c59
4 changed files with 40 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
Syntax: name_short|Name|Username|email (opt: |ex) (opt: ;;group1|group2|group3...) !!Remember to set the env var authors_file!! Syntax: name_short|Name|Username|email (opt: |ex) (opt: ;;group1|group2|group3...)
+7
View File
@@ -31,6 +31,12 @@ var rootCmD = &cobra.Command{
// check if the print flag is set // check if the print flag is set
pflag, _ := cmd.Flags().GetBool("print") pflag, _ := cmd.Flags().GetBool("print")
tflag, _ := cmd.Flags().GetBool("test_print") tflag, _ := cmd.Flags().GetBool("test_print")
aflag, _ := cmd.Flags().GetBool("authors")
if aflag {
tui.Entry()
os.Exit(0)
}
// run execute commands again as root run will not call this part // run execute commands again as root run will not call this part
// redundant check for now but will be useful later when we add tui // redundant check for now but will be useful later when we add tui
wrap_around: wrap_around:
@@ -96,4 +102,5 @@ func init() {
rootCmD.Flags().BoolP("print", "p", false, "Prints the commit message to the console") rootCmD.Flags().BoolP("print", "p", false, "Prints the commit message to the console")
rootCmD.Flags().BoolP("test_print", "t", false, "Prints the commit message to the console without running the git commit command") rootCmD.Flags().BoolP("test_print", "t", false, "Prints the commit message to the console without running the git commit command")
rootCmD.Flags().BoolP("message", "m", false, "Does nothing but allows for -m to be used in the command") rootCmD.Flags().BoolP("message", "m", false, "Does nothing but allows for -m to be used in the command")
rootCmD.Flags().BoolP("authors", "a", false, "Runs the author list TUI")
} }
+2 -1
View File
@@ -5,10 +5,11 @@ package tui
import ( import (
"fmt" "fmt"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"os" "os"
"strings" "strings"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
+25 -2
View File
@@ -36,8 +36,31 @@ func CheckAuthorFile() string {
println("Error reading response") println("Error reading response")
} }
if response == "y" { if response == "y" {
//TODO: Tui response to create author file if authorfile == "" {
//createAuthorFile(authorfile) fmt.Println("author_file environment variable not set using default location:")
config, err := os.UserConfigDir()
if err != nil {
fmt.Println("Error getting user config directory")
os.Exit(1)
}
authorfile = config + "/cocommit/authors"
fmt.Println(authorfile)
}
// create the author file
file, err := os.Create(authorfile)
if err != nil {
fmt.Println("Error creating file: ", err)
os.Exit(1)
}
defer file.Close()
// write the header to the file
file.WriteString("Syntax: name_short|Name|Username|email (opt: |ex) (opt: ;;group1|group2|group3...)\n")
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)
} }