From 923f94c314e3c21820bb4a6ba9f6f379f7dd25f0 Mon Sep 17 00:00:00 2001 From: Theis Date: Sat, 20 Apr 2024 22:20:07 +0200 Subject: [PATCH] refactor: sort users printout --- src_code/go_src/cocommit.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src_code/go_src/cocommit.go b/src_code/go_src/cocommit.go index bc24e6d..8534842 100644 --- a/src_code/go_src/cocommit.go +++ b/src_code/go_src/cocommit.go @@ -7,6 +7,7 @@ import ( "os/exec" "regexp" "slices" + "sort" "strings" ) @@ -56,7 +57,7 @@ func main() { group_info = append(group_info, strings.Split(input[1], "|")...) } info := strings.Split(input_str, "|") - usr := user{username: info[2], email: info[3], names: info[0]+ "/" + info[1]} + usr := user{username: info[2], email: info[3], names: info[0] + "/" + info[1]} users[info[0]] = usr users[info[1]] = usr // Adds users with the ex tag to the defExclude list @@ -195,12 +196,15 @@ func NoInput(args []string, users map[string]user) { if len(args) == 1 && args[0] == "users" { println("List of users:\nFormat: / -> Username: Email: ") seen_users := []user{} + user_sb := []string{} for name, usr := range users { if !slices.Contains(seen_users, usr) { - println(users[name].names, " ->", " Username:", usr.username, " Email:", usr.email) - seen_users = append(seen_users, usr) + user_sb = append(user_sb, 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(1) } // if calling binary with nothing or only string