diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-07-04 22:18:49 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-07-04 22:18:49 +0530 |
commit | 2689541cbbba044153c33fb1b36d691514916139 (patch) | |
tree | c7274666127b8a038b885353c541c14f32dfa264 /cmd | |
parent | 2bb89f25599f48c4953801298c4f9ef8dee12246 (diff) |
added --id flag to search and episodes and chapters command
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/chapters.go | 22 | ||||
-rw-r--r-- | cmd/episodes.go | 24 | ||||
-rw-r--r-- | cmd/status.go | 3 |
3 files changed, 31 insertions, 18 deletions
diff --git a/cmd/chapters.go b/cmd/chapters.go index 87d887b..220953e 100644 --- a/cmd/chapters.go +++ b/cmd/chapters.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/MikunoNaka/macli/ui" "github.com/MikunoNaka/macli/mal" + m "github.com/MikunoNaka/MAL2Go/v3/manga" "github.com/spf13/cobra" ) @@ -41,8 +42,13 @@ var chaptersCmd = &cobra.Command{ " - \x1b[33m`macli chapters -s -2 <anime-name>`\x1b[0m to decrement the chapters by 2\n", Run: func(cmd *cobra.Command, args []string) { mal.Init() + var selectedManga m.Manga + if entryId > 0 { + selectedManga = mal.GetMangaData(entryId, []string{"my_list_status", "num_chapters"}) + } + searchInput := strings.Join(args, " ") - if searchInput == "" { + if searchInput == "" && entryId < 1 { var promptText string if queryOnlyMode { promptText = "Search Manga to Get Amount of Chapters Read For: " @@ -64,20 +70,21 @@ var chaptersCmd = &cobra.Command{ } } - manga := ui.MangaSearch("Select Manga:", searchInput) - selectedManga := mal.GetMangaData(manga.Id, []string{"my_list_status", "num_chapters"}) - prevChRead := selectedManga.MyListStatus.ChaptersRead + if entryId < 1 { + manga := ui.MangaSearch("Select Manga:", searchInput) + selectedManga = mal.GetMangaData(manga.Id, []string{"my_list_status", "num_chapters"}) + } if queryOnlyMode { - fmt.Printf("\x1b[35m%s\x1b[0m Chapters :: \x1b[1;36m%d\x1b[0m / \x1b[1;33m%d\x1b[0m Read\n", manga.Title, prevChRead, selectedManga.NumChapters) + fmt.Printf("%s / \x1b[1;33m%d\n", ui.CreateChapterUpdateConfirmationMessage(selectedManga.Title, selectedManga.MyListStatus.ChaptersRead, -1), selectedManga.NumChapters) os.Exit(0) } if chInput == "" { ui.ChapterInput(selectedManga) } else { - resp := mal.SetChapters(manga.Id, prevChRead, chInput) - fmt.Println(ui.CreateChapterUpdateConfirmationMessage(manga.Title, prevChRead, resp.ChaptersRead)) + resp := mal.SetChapters(selectedManga.Id, selectedManga.MyListStatus.ChaptersRead, chInput) + fmt.Println(ui.CreateChapterUpdateConfirmationMessage(selectedManga.Title, resp.ChaptersRead, selectedManga.MyListStatus.ChaptersRead)) } }, } @@ -90,4 +97,5 @@ func init() { chaptersCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") chaptersCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") chaptersCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") + chaptersCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") } diff --git a/cmd/episodes.go b/cmd/episodes.go index 0746712..13dd4ab 100644 --- a/cmd/episodes.go +++ b/cmd/episodes.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/MikunoNaka/macli/ui" "github.com/MikunoNaka/macli/mal" + a "github.com/MikunoNaka/MAL2Go/v3/anime" "github.com/spf13/cobra" ) @@ -41,8 +42,13 @@ var episodesCmd = &cobra.Command{ " - \x1b[33m`macli episodes -s -2 <anime-name>`\x1b[0m to decrement the episodes by 2\n", Run: func(cmd *cobra.Command, args []string) { mal.Init() + var selectedAnime a.Anime + if entryId > 0 { + selectedAnime = mal.GetAnimeData(entryId, []string{"my_list_status", "num_episodes"}) + } + searchInput := strings.Join(args, " ") - if searchInput == "" { + if searchInput == "" && entryId < 1 { var promptText string if queryOnlyMode { promptText = "Search Anime to Get Amount of Episodes Watched for: " @@ -64,23 +70,22 @@ var episodesCmd = &cobra.Command{ } } - anime := ui.AnimeSearch("Select Anime:", searchInput) - selectedAnime := mal.GetAnimeData(anime.Id, []string{"my_list_status", "num_episodes"}) - prevEpWatched := selectedAnime.MyListStatus.EpWatched + if entryId < 1 { + anime := ui.AnimeSearch("Select Anime:", searchInput) + selectedAnime = mal.GetAnimeData(anime.Id, []string{"my_list_status", "num_episodes"}) + } if queryOnlyMode { - fmt.Printf("\x1b[35m%s\x1b[0m Episodes :: \x1b[1;36m%d\x1b[0m / \x1b[1;33m%d\x1b[0m Watched\n", anime.Title, prevEpWatched, selectedAnime.NumEpisodes) + fmt.Printf("%s / \x1b[1;33m%d\n", ui.CreateEpisodeUpdateConfirmationMessage(selectedAnime.Title, selectedAnime.MyListStatus.EpWatched, -1), selectedAnime.NumEpisodes) os.Exit(0) } if epInput == "" { ui.EpisodeInput(selectedAnime) } else { - resp := mal.SetEpisodes(anime.Id, prevEpWatched, epInput) - fmt.Println(ui.CreateEpisodeUpdateConfirmationMessage(anime.Title, prevEpWatched, resp.EpWatched)) + resp := mal.SetEpisodes(selectedAnime.Id, selectedAnime.MyListStatus.EpWatched, epInput) + fmt.Println(ui.CreateEpisodeUpdateConfirmationMessage(selectedAnime.Title, resp.EpWatched, selectedAnime.MyListStatus.EpWatched)) } - - }, } @@ -92,4 +97,5 @@ func init() { episodesCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") episodesCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") episodesCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") + episodesCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") } diff --git a/cmd/status.go b/cmd/status.go index ba5d047..1e80c7b 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -128,8 +128,7 @@ func setMangaStatus(statusInput, searchInput string) { ui.MangaStatusMenu(selectedManga) } else { resp := mal.SetMangaStatus(selectedManga.Id, statusInput) - fmt.Println(resp.Status) - fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedManga.Title, resp.Status, selectedManga.MyListStatus.Status)) + fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedManga.Title, selectedManga.MyListStatus.Status, resp.Status)) } } |