aboutsummaryrefslogtreecommitdiff
path: root/cmd/episodes.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-30 20:15:05 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-30 20:15:05 +0530
commita3a7b41179d8abe9edc705db6b14063e95c459fa (patch)
tree935506bc5ddf9c6a28b45b619b370178f1dc13d4 /cmd/episodes.go
parent599139984e50d769bb97332ed5a327cf6d41ba37 (diff)
added --query option to episodes and chapters command
Diffstat (limited to 'cmd/episodes.go')
-rw-r--r--cmd/episodes.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/cmd/episodes.go b/cmd/episodes.go
index 203e6e3..e26e190 100644
--- a/cmd/episodes.go
+++ b/cmd/episodes.go
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
+ "os"
"fmt"
"strings"
"github.com/MikunoNaka/macli/ui"
@@ -41,20 +42,38 @@ var episodesCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
searchInput := strings.Join(args, " ")
if searchInput == "" {
- searchInput = ui.TextInput("Search Anime To Set Episodes For: ", "Search can't be blank.")
+ var promptText string
+ if queryOnlyMode {
+ promptText = "Search Anime to Get Amount of Episodes Watched for: "
+ } else {
+ promptText = "Search Anime To Set Episodes For: "
+ }
+ searchInput = ui.TextInput(promptText, "Search can't be blank.")
}
- epInput, err := cmd.Flags().GetString("set-value")
- if err != nil {
- fmt.Println("Error while reading --set-value flag.", err.Error())
+ var (
+ epInput string
+ err error
+ )
+ if !queryOnlyMode {
+ epInput, err = cmd.Flags().GetString("set-value")
+ if err != nil {
+ fmt.Println("Error while reading \x1b[33m--set-value\x1b[0m flag.", err.Error())
+ os.Exit(1)
+ }
}
anime := ui.AnimeSearch("Select Anime:", searchInput)
- animeData := mal.GetAnimeData(anime.Id, []string{"my_list_status"})
- prevEpWatched := animeData.MyListStatus.EpWatched
+ selectedAnime := mal.GetAnimeData(anime.Id, []string{"my_list_status", "num_episodes"})
+ prevEpWatched := selectedAnime.MyListStatus.EpWatched
+
+ if queryOnlyMode {
+ fmt.Printf("You Have watched \x1b[1;36m%d\x1b[0m out of \x1b[1;33m%d\x1b[0m episodes from \x1b[35m%s\x1b[0m\n", prevEpWatched, selectedAnime.NumEpisodes, anime.Title)
+ os.Exit(0)
+ }
if epInput == "" {
- ui.EpisodeInput(anime)
+ ui.EpisodeInput(selectedAnime)
} else {
resp := mal.SetEpisodes(anime.Id, prevEpWatched, epInput)
fmt.Println(ui.CreateEpisodeUpdateConfirmationMessage(anime.Title, prevEpWatched, resp.EpWatched))