feat: added commitizen support (due to cmd execution styles this will not be in the test suite)

Due to the way that the interactive cli call has to be made there is no
good way to automate the tests for it without spending a long time
trying to understand go pipes. since this is more of an extra feature
anyways I am fine with leaving this somewhat untested especially since
it is small isolated code
This commit is contained in:
Slug-Boi
2024-10-31 21:24:17 +01:00
parent c92079f6cd
commit b1c4df81c8
5 changed files with 143 additions and 48 deletions
+35 -34
View File
@@ -1,14 +1,15 @@
package cmd
import (
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/tui"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"os"
"os/exec"
"slices"
"sort"
"strings"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/tui"
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
"github.com/spf13/cobra"
)
@@ -17,43 +18,43 @@ var authorfile = utils.Find_authorfile()
// usersCmd represents the users command
func UsersCmd() *cobra.Command {
return &cobra.Command{
Use: "users",
Short: "Displays all users from the author file located at: " + authorfile,
Long: `Displays all users from the author file located at: ` + authorfile,
Run: func(cmd *cobra.Command, args []string) {
//TODO: make this print a bit prettier (sort it and maybe use a table)
// check if the no pretty print flag is set
np, _ := cmd.Flags().GetBool("np")
if np {
println("List of users:\nFormat: <shortname>/<name> -> Username: <username> Email: <email>")
seen_users := []utils.User{}
user_sb := []string{}
for name, usr := range utils.Users {
if !slices.Contains(seen_users, usr) {
user_sb = append(user_sb, utils.Users[name].Names+" ->"+" Username: "+usr.Username+" Email: "+usr.Email+"\n")
seen_users = append(seen_users, usr)
Use: "users",
Short: "Displays all users from the author file located at: " + authorfile,
Long: `Displays all users from the author file located at: ` + authorfile,
Run: func(cmd *cobra.Command, args []string) {
//TODO: make this print a bit prettier (sort it and maybe use a table)
// check if the no pretty print flag is set
np, _ := cmd.Flags().GetBool("np")
if np {
println("List of users:\nFormat: <shortname>/<name> -> Username: <username> Email: <email>")
seen_users := []utils.User{}
user_sb := []string{}
for name, usr := range utils.Users {
if !slices.Contains(seen_users, usr) {
user_sb = append(user_sb, utils.Users[name].Names+" ->"+" Username: "+usr.Username+" Email: "+usr.Email+"\n")
seen_users = append(seen_users, usr)
}
}
sort.Strings(user_sb)
println(strings.Join(user_sb, ""))
os.Exit(0)
}
sort.Strings(user_sb)
println(strings.Join(user_sb, ""))
os.Exit(0)
}
bat_check := exec.Command("which", "bat")
out, _ := bat_check.CombinedOutput()
if string(out) == "" {
tui.Entry_US(authorfile)
os.Exit(0)
}
bat := exec.Command("bat", authorfile)
bat.Stdout = os.Stdout
bat.Stderr = os.Stderr
bat.Run()
},
}
bat_check := exec.Command("which", "bat")
out, _ := bat_check.CombinedOutput()
if string(out) == "" {
tui.Entry_US(authorfile)
os.Exit(0)
}
bat := exec.Command("bat", authorfile)
bat.Stdout = os.Stdout
bat.Stderr = os.Stderr
bat.Run()
},
}
}
func init() {
usersCmd := UsersCmd()
rootCmD.AddCommand(usersCmd)
rootCmd.AddCommand(usersCmd)
usersCmd.Flags().BoolP("np", "n", false, "No pretty print of the users")
}