diff options
-rw-r--r-- | cmd/search.go | 66 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 |
3 files changed, 48 insertions, 24 deletions
diff --git a/cmd/search.go b/cmd/search.go index 0c166b2..c77ba44 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -25,6 +25,8 @@ import ( "github.com/MikunoNaka/macli/mal" "github.com/MikunoNaka/macli/ui" + a "github.com/MikunoNaka/MAL2Go/v3/anime" + m "github.com/MikunoNaka/MAL2Go/v3/manga" "github.com/spf13/cobra" ) @@ -56,35 +58,57 @@ var searchCmd = &cobra.Command { } func searchManga(searchInput string) { - if entryId > 0 { - selectedManga := mal.GetMangaData(entryId, []string{"my_list_status", "title"}) - fmt.Println("Selected: \x1b[35m" + selectedManga.Title + "\x1b[0m") - ui.MangaActionMenu(selectedManga.MyListStatus.Status != "")(selectedManga) + var selectedManga m.Manga + mangaId := entryId + fields := []string{} + + if entryId < 1 { + if searchInput == "" { + searchInput = ui.TextInput("Search Manga: ", "Search can't be blank.") + } + manga := ui.MangaSearch("Select Manga:", searchInput) + mangaId = manga.Id + fields = []string{"my_list_status", "num_chapters"} + } + + selectedManga = mal.GetMangaData(mangaId, fields) + + if queryOnlyMode { + fmt.Println("coming soon", selectedManga) os.Exit(0) } - if searchInput == "" { - searchInput = ui.TextInput("Search Manga: ", "Search can't be blank.") + + if entryId > 1 { + fmt.Println("Selected: \x1b[35m" + selectedManga.Title + "\x1b[0m") } - manga := ui.MangaSearch("Select Manga:", searchInput) - selectedManga := mal.GetMangaData(manga.Id, []string{"my_list_status", "num_chapters"}) - mangaIsAdded := selectedManga.MyListStatus.Status != "" - ui.MangaActionMenu(mangaIsAdded)(selectedManga) + ui.MangaActionMenu(selectedManga.MyListStatus.Status != "")(selectedManga) } func searchAnime(searchInput string) { - if entryId > 0 { - selectedAnime := mal.GetAnimeData(entryId, []string{"my_list_status"}) - fmt.Println("Selected: \x1b[35m" + selectedAnime.Title + "\x1b[0m") - ui.AnimeActionMenu(selectedAnime.MyListStatus.Status != "")(selectedAnime) + var selectedAnime a.Anime + animeId := entryId + fields := []string{} + + if entryId < 1 { + if searchInput == "" { + searchInput = ui.TextInput("Search Anime: ", "Search can't be blank.") + } + anime := ui.AnimeSearch("Select Anime:", searchInput) + animeId = anime.Id + fields = []string{"my_list_status", "num_episodes"} + } + + selectedAnime = mal.GetAnimeData(animeId, fields) + + if queryOnlyMode { + fmt.Println("coming soon", selectedAnime) os.Exit(0) } - if searchInput == "" { - searchInput = ui.TextInput("Search Anime: ", "Search can't be blank.") + + if entryId > 1 { + fmt.Println("Selected: \x1b[35m" + selectedAnime.Title + "\x1b[0m") } - anime := ui.AnimeSearch("Select Anime:", searchInput) - selectedAnime := mal.GetAnimeData(anime.Id, []string{"my_list_status", "num_episodes"}) - animeIsAdded := selectedAnime.MyListStatus.Status != "" - ui.AnimeActionMenu(animeIsAdded)(selectedAnime) + ui.AnimeActionMenu(selectedAnime.MyListStatus.Status != "")(selectedAnime) } func init() { @@ -94,6 +118,6 @@ func init() { searchCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") searchCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") searchCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") - searchCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") searchCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") + searchCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") } @@ -3,7 +3,7 @@ module github.com/MikunoNaka/macli go 1.18 require ( - github.com/MikunoNaka/MAL2Go/v3 v3.0.1 + github.com/MikunoNaka/MAL2Go/v3 v3.1.0 github.com/manifoldco/promptui v0.9.0 github.com/spf13/cobra v1.4.0 github.com/zalando/go-keyring v0.2.1 @@ -1,5 +1,5 @@ -github.com/MikunoNaka/MAL2Go/v3 v3.0.1 h1:QYQkBtNRqCk+E+TTfN3Kx/jm6lkFZZf631MnPTnk5PI= -github.com/MikunoNaka/MAL2Go/v3 v3.0.1/go.mod h1:K8GX5VGSfblL+/6l30CA6US3jIbiwBEpf/n6b/RqKKs= +github.com/MikunoNaka/MAL2Go/v3 v3.1.0 h1:ZTzMnpWpe4J6Gde64EibSIvemz1kJVXsqGWZpdUPL6Q= +github.com/MikunoNaka/MAL2Go/v3 v3.1.0/go.mod h1:K8GX5VGSfblL+/6l30CA6US3jIbiwBEpf/n6b/RqKKs= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= |