diff --git a/src_code/go_src/author.txt b/src_code/go_src/author.txt index 76b9873..34a123f 100644 --- a/src_code/go_src/author.txt +++ b/src_code/go_src/author.txt @@ -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...) diff --git a/src_code/go_src/cmd/root.go b/src_code/go_src/cmd/root.go index 6b335ca..fd01727 100644 --- a/src_code/go_src/cmd/root.go +++ b/src_code/go_src/cmd/root.go @@ -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") } diff --git a/src_code/go_src/cmd/tui/tui_author.go b/src_code/go_src/cmd/tui/tui_author.go index 6dfc04e..93d966a 100644 --- a/src_code/go_src/cmd/tui/tui_author.go +++ b/src_code/go_src/cmd/tui/tui_author.go @@ -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" diff --git a/src_code/go_src/cmd/utils/author_file_utils.go b/src_code/go_src/cmd/utils/author_file_utils.go index 1c3a2fe..62ba9d2 100644 --- a/src_code/go_src/cmd/utils/author_file_utils.go +++ b/src_code/go_src/cmd/utils/author_file_utils.go @@ -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)