From 8fb49796e37d2bf955d8ffa521f6bcda4f36b766 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 2 Oct 2022 20:46:50 +0530 Subject: Automatically select nth search result with --auto-select flag --- ui/search.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ui') diff --git a/ui/search.go b/ui/search.go index 60089f3..a8e8f51 100644 --- a/ui/search.go +++ b/ui/search.go @@ -40,6 +40,15 @@ var AnimeSearchFields []string = []string { // only search animes probably only now func AnimeSearch(label, searchString string) a.Anime { animes := mal.SearchAnime(searchString, AnimeSearchFields) + // don't show selection prompt if --auto-select is passed + if mal.AutoSel > 0 { + if len(animes) > 0 { + return animes[0] + } else { + fmt.Println("Error: Empty response from MyAnimeList while searching for anime.") + os.Exit(1) + } + } for i, anime := range animes { animes[i].DurationSeconds = anime.DurationSeconds / 60 @@ -148,6 +157,15 @@ var MangaSearchFields []string = []string { func MangaSearch(label, searchString string) m.Manga { mangas := mal.SearchManga(searchString, MangaSearchFields) + // don't show selection prompt if --auto-select is passed + if mal.AutoSel > 0 { + if len(mangas) > 0 { + return mangas[0] + } else { + fmt.Println("Error: Empty response from MyAnimeList while searching for manga.") + os.Exit(1) + } + } for i, manga := range mangas { /* I cant find a way to add functions to the details template -- cgit v1.2.3