mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
refactor: update check author file function and create new flag to enter author list tui mode
This commit is contained in:
@@ -31,6 +31,12 @@ var rootCmD = &cobra.Command{
|
||||
// check if the print flag is set
|
||||
pflag, _ := cmd.Flags().GetBool("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
|
||||
// redundant check for now but will be useful later when we add tui
|
||||
wrap_around:
|
||||
@@ -96,4 +102,5 @@ func init() {
|
||||
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("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")
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
@@ -36,8 +36,31 @@ func CheckAuthorFile() string {
|
||||
println("Error reading response")
|
||||
}
|
||||
if response == "y" {
|
||||
//TODO: Tui response to create author file
|
||||
//createAuthorFile(authorfile)
|
||||
if 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 {
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -59,14 +82,14 @@ func DeleteOneAuthor(author string) {
|
||||
defer file.Close()
|
||||
|
||||
// create regex to capture author line
|
||||
regexp, err := regexp.Compile(fmt.Sprintf("^(.+\\|%s\\|.+|%s\\|.+\\|.+)$",author,author))
|
||||
regexp, err := regexp.Compile(fmt.Sprintf("^(.+\\|%s\\|.+|%s\\|.+\\|.+)$", author, author))
|
||||
if err != nil {
|
||||
fmt.Println("Error compiling regex: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var b []byte
|
||||
buf := bytes.NewBuffer(b)
|
||||
buf := bytes.NewBuffer(b)
|
||||
|
||||
// create a scanner for the file
|
||||
scanner := bufio.NewScanner(file)
|
||||
@@ -85,10 +108,10 @@ func DeleteOneAuthor(author string) {
|
||||
|
||||
}
|
||||
// remove the last newline character
|
||||
buf.Truncate(buf.Len()-1)
|
||||
buf.Truncate(buf.Len() - 1)
|
||||
|
||||
file.Truncate(0)
|
||||
file.Seek(0,0)
|
||||
file.Seek(0, 0)
|
||||
buf.WriteTo(file)
|
||||
|
||||
RemoveUser(author)
|
||||
|
||||
Reference in New Issue
Block a user