aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-06 23:23:01 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-06 23:23:01 +0530
commit83a39dbebed42b9bd779d86b4fcf30a0f5348d87 (patch)
treeced0a3cbcde63fdeb01e678191b3eee07e056ad4
parentb5a8c767660fde8b73fee1ea0b261b28e35ccc62 (diff)
added manga and nsfw results in list command
-rw-r--r--cmd/list.go8
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--mal/list.go4
-rw-r--r--ui/list.go (renamed from ui/animelist.go)30
5 files changed, 41 insertions, 7 deletions
diff --git a/cmd/list.go b/cmd/list.go
index f0e4327..b9c82d9 100644
--- a/cmd/list.go
+++ b/cmd/list.go
@@ -66,8 +66,11 @@ var listCmd = &cobra.Command{
os.Exit(1)
}
-
- ui.AnimeList(mal.AnimeList(user, status, sort, nsfw))
+ if mangaMode {
+ ui.MangaList(mal.MangaList(user, status, sort, nsfw))
+ } else {
+ ui.AnimeList(mal.AnimeList(user, status, sort, nsfw))
+ }
},
}
@@ -78,4 +81,5 @@ func init() {
listCmd.Flags().StringP("user", "", "@me", "User (@me or blank for self)")
listCmd.Flags().StringP("sort", "", "list_score", "Sort the list")
listCmd.Flags().BoolP("include-nsfw", "", false, "Include NSFW results")
+ listCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode")
}
diff --git a/go.mod b/go.mod
index 406df62..1811c55 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/MikunoNaka/macli
go 1.18
require (
- github.com/MikunoNaka/MAL2Go/v4 v4.0.0
+ github.com/MikunoNaka/MAL2Go/v4 v4.0.1
github.com/jedib0t/go-pretty/v6 v6.3.3
github.com/manifoldco/promptui v0.9.0
github.com/spf13/cobra v1.4.0
diff --git a/go.sum b/go.sum
index 5779077..e44aa18 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/MikunoNaka/MAL2Go/v4 v4.0.0 h1:8T/JCs7vu5pANSCPCK1ab03LLDX6HLqypGB88MmeYnE=
-github.com/MikunoNaka/MAL2Go/v4 v4.0.0/go.mod h1:SMOngKqH871nz/jWDUSD3t09ArGsPMrFH6l//diIhgw=
+github.com/MikunoNaka/MAL2Go/v4 v4.0.1 h1:53XINjSE+V2UtKyddsFDOIySHREbkZsU9srRA98ONqU=
+github.com/MikunoNaka/MAL2Go/v4 v4.0.1/go.mod h1:SMOngKqH871nz/jWDUSD3t09ArGsPMrFH6l//diIhgw=
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=
diff --git a/mal/list.go b/mal/list.go
index ec0c634..82b4938 100644
--- a/mal/list.go
+++ b/mal/list.go
@@ -27,7 +27,7 @@ import (
// TODO: return all the list items using loop
func AnimeList(user, status, sort string, nsfw bool) []a.Anime {
- res, _, err := userAnimeClient.GetAnimeList(user, status, sort, 1000, 0, nsfw, []string{"title", "list_status", "num_episodes", "media_type"})
+ res, _, err := userAnimeClient.GetAnimeList(user, status, sort, 1000, 0, nsfw, []string{"title", "num_episodes", "media_type"})
if err != nil {
fmt.Println(err)
os.Exit(1)
@@ -37,7 +37,7 @@ func AnimeList(user, status, sort string, nsfw bool) []a.Anime {
// TODO: return all the list items using loop
func MangaList(user, status, sort string, nsfw bool) []m.Manga {
- res, _, err := userMangaClient.GetMangaList(user, status, sort, 1000, 0, nsfw, []string{"title", "my_list_status", "num_chapters"})
+ res, _, err := userMangaClient.GetMangaList(user, status, sort, 1000, 0, nsfw, []string{"title", "num_chapters", "num_volumes", "media_type"})
if err != nil {
fmt.Println(err)
os.Exit(1)
diff --git a/ui/animelist.go b/ui/list.go
index c256666..f1eb10e 100644
--- a/ui/animelist.go
+++ b/ui/list.go
@@ -20,6 +20,7 @@ package ui
import (
a "github.com/MikunoNaka/MAL2Go/v4/anime"
+ m "github.com/MikunoNaka/MAL2Go/v4/manga"
"github.com/jedib0t/go-pretty/v6/table"
"fmt"
"os"
@@ -52,3 +53,32 @@ func AnimeList(animes []a.Anime) {
t.AppendFooter(table.Row{len(animes), "", "", ""})
t.Render()
}
+
+func MangaList(mangas []m.Manga) {
+ t := table.NewWriter()
+ t.SetOutputMirror(os.Stdout)
+
+ t.AppendHeader(table.Row{"#", "Title", "ID", "Score", "Type", "Status", "Chapters", "Volumes"})
+
+ for index, manga := range mangas {
+ status := manga.ListStatus.Status
+ score := manga.ListStatus.Score
+
+ formattedStatus := GetColorCodeByStatus(status) + FormatStatus(status) + "\x1b[0m"
+ formattedScore := FormatScore(score)
+
+ // TODO: format it
+ formattedMediaType := manga.MediaType
+
+ chapterProgress := fmt.Sprintf("%d/%d", manga.ListStatus.ChaptersRead, manga.NumChapters)
+ volumeProgress := fmt.Sprintf("%d/%d", manga.ListStatus.VolumesRead, manga.NumVolumes)
+
+ t.AppendRow([]interface{}{
+ index + 1, manga.Title, manga.Id, formattedScore, formattedMediaType, formattedStatus, chapterProgress, volumeProgress,
+ })
+ }
+
+ t.AppendSeparator()
+ t.AppendFooter(table.Row{len(mangas), "", "", ""})
+ t.Render()
+}