From a92cdf9c89a0530f72d1744e132dfdc542fe4b46 Mon Sep 17 00:00:00 2001 From: joop Date: Sat, 2 Apr 2022 05:56:34 +0100 Subject: Now sorting works --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 10a72b1..1976f7f 100644 --- a/main.go +++ b/main.go @@ -333,7 +333,6 @@ func main() { fmt.Println(prayer.Text) fmt.Println("ID:", prayer.Id) fmt.Println("Author:", prayer.Author()) - matchcode: for code == "" { // Ask for a keyword fmt.Print("Input a keyword for this prayer, skip to pick another one or code to enter the code manually: ") @@ -350,9 +349,9 @@ func main() { // Check for the prayer text of each prayer in // PrayersWithCode if there is a match with the keyword // and add it to Matches - for _, prayer := range PrayersWithCode { - if strings.Contains(prayer.Text, keyword) { - Matches = append(Matches, prayer) + for _, pr := range PrayersWithCode { + if strings.Contains(pr.Text, keyword) { + Matches = append(Matches, pr) } } // If there are no matches, ask again @@ -363,7 +362,9 @@ func main() { // Ask which of the matches to use fmt.Println("Found " + strconv.Itoa(len(Matches)) + " matches.") fmt.Println("Which of the following matches?") - for i, match := range Matches { + sortedMatches := NewPrayerLengthSort(Matches, prayer) + sortedMatches.Sort() + for i, match := range sortedMatches.Prayers() { fmt.Println(i+1, ":", match.Text) fmt.Print("Does this match? (y/n/skip) ") answer := prompt.MustRead[string]() @@ -373,7 +374,7 @@ func main() { break } if answer == "skip" { - break matchcode + break } } } -- cgit v1.2.3-70-g09d2