Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
### ✨ What's New
- You can now find the docs on https://chibi-cli.pages.dev/
- You can now install chibi in windows via winget. To do so, type in
- The `ls` command now shows Rewatching/Rereading Media along with Current Media. The Rewatching/Rereading media will be marked by **"(R)"** before the media title.
- You can now pass incremental or decremental progress to `update` command. For example,

To increment progress of a media by 2,
```shell
winget install CosmicPredator.Chibi
$ chibi update 8861 -p +2
```

To decrement progress of a media by 5,
```shell
$ chibi update 8861 -p -5
```
- Added install/uninstall scripts for linux and macOS.

### πŸ› Bug Fixes
- Undo gitignoring `go.sum` for nix flake builds.
- None for now πŸ‘½οΈ
4 changes: 2 additions & 2 deletions cmd/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func handleMediaAdd(mediaId int) {
mediaUpdate := internal.NewMediaUpdate()
if mediaAddStatus == "CURRENT" {
currDate := fmt.Sprintf("%d/%d/%d", time.Now().Day(), time.Now().Month(), time.Now().Year())
err := mediaUpdate.Get(true, mediaId, 0, mediaAddStatus, currDate)
err := mediaUpdate.Get(true, mediaId, "0", mediaAddStatus, currDate)
if err != nil {
ErrorMessage(err.Error())
}
} else {
err := mediaUpdate.Get(true, mediaId, 0, mediaAddStatus, "")
err := mediaUpdate.Get(true, mediaId, "0", mediaAddStatus, "")
if err != nil {
ErrorMessage(err.Error())
}
Expand Down
39 changes: 23 additions & 16 deletions cmd/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ func handleLs() {
}

rows := [][]string{}
for _, i := range mediaList.Data.MediaListCollection.Lists[0].Entries {
var progress string
if mediaType == "ANIME" {
progress = fmt.Sprintf("%d/%d", i.Progress, i.Media.Episodes)
} else {
progress = fmt.Sprintf("%d/%d", i.Progress, i.Media.Chapters)
}

rows = append(rows, []string{
strconv.Itoa(i.Media.Id),
i.Media.Title.UserPreferred,
progress,
})
for _, lists := range mediaList.Data.MediaListCollection.Lists {
for _, entry := range lists.Entries {
var progress string
if mediaType == "ANIME" {
progress = fmt.Sprintf("%d/%d", entry.Progress, entry.Media.Episodes)
} else {
progress = fmt.Sprintf("%d/%d", entry.Progress, entry.Media.Chapters)
}

if lists.Status == "REPEATING" {
entry.Media.Title.UserPreferred = "(R) " + entry.Media.Title.UserPreferred
}

rows = append(rows, []string{
strconv.Itoa(entry.Media.Id),
entry.Media.Title.UserPreferred,
progress,
})
}
}

// get size of terminal
Expand Down Expand Up @@ -85,9 +92,9 @@ func handleLs() {
}

var mediaListCmd = &cobra.Command{
Use: "list",
Short: "List your current anime/manga list",
Aliases: []string{ "ls" },
Use: "list",
Short: "List your current anime/manga list",
Aliases: []string{"ls"},
Run: func(cmd *cobra.Command, args []string) {
handleLs()
},
Expand All @@ -98,6 +105,6 @@ func init() {
&listMediaType, "type", "t", "anime", "Type of media. for anime, pass 'anime' or 'a', for manga, use 'manga' or 'm'",
)
mediaListCmd.Flags().StringVarP(
&listStatus, "status", "s", "watching", "Status of the media. Can be 'watching/w or reading/r', 'planning/p', 'completed/c', 'dropped/d', 'paused/ps', 'repeating/rp'",
&listStatus, "status", "s", "watching", "Status of the media. Can be 'watching/w or reading/r', 'planning/p', 'completed/c', 'dropped/d', 'paused/ps'",
)
}
25 changes: 16 additions & 9 deletions cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ import (
)

// TODO: Update progress relatively. For example "+2", "-10" etc.,
var progress int
var progress string

func handleUpdate(mediaId int) {
CheckIfTokenExists()
if progress == 0 {
fmt.Println(
ERROR_MESSAGE_TEMPLATE.Render("The flag 'progress' should be greater than 0."),
)

progressInt, err := strconv.Atoi(progress)
if err == nil {
if progressInt == 0 {
fmt.Println(
ERROR_MESSAGE_TEMPLATE.Render("The flag 'progress' should be greater than 0."),
)
}
}

mediaUpdate := internal.NewMediaUpdate()
err := mediaUpdate.Get(false, mediaId, progress, "", "")
err = mediaUpdate.Get(false, mediaId, progress, "", "")

if err != nil {
ErrorMessage(err.Error())
Expand All @@ -35,8 +39,11 @@ func handleUpdate(mediaId int) {
var mediaUpdateCmd = &cobra.Command{
Use: "update [id]",
Short: "Update a list entry",
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 2 {
progress = args[1]
}
id, err := strconv.Atoi(args[0])
if err != nil {
fmt.Println(
Expand All @@ -48,11 +55,11 @@ var mediaUpdateCmd = &cobra.Command{
}

func init() {
mediaUpdateCmd.Flags().IntVarP(
mediaUpdateCmd.Flags().StringVarP(
&progress,
"progress",
"p",
0,
"0",
"The number of episodes/chapter to update",
)
}
56 changes: 34 additions & 22 deletions internal/media_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ package internal

import "github.com/CosmicPredator/chibi/types"

type ListCollection struct {
Lists []struct {
Status string `json:"status"`
Entries []struct {
Progress int `json:"progress"`
ProgressVolumes int `json:"progressVolumes"`
Media struct {
Id int `json:"id"`
Title struct {
UserPreferred string `json:"userPreferred"`
} `json:"title"`
Chapters int `json:"chapters"`
Volumes int `json:"volumes"`
Episodes int `json:"episodes"`
} `json:"media"`
} `json:"entries"`
} `json:"lists"`
}

type MediaList struct {
Data struct {
MediaListCollection struct {
Lists []struct {
Entries []struct {
Progress int `json:"progress"`
ProgressVolumes int `json:"progressVolumes"`
Media struct {
Id int `json:"id"`
Title struct {
UserPreferred string `json:"userPreferred"`
} `json:"title"`
Chapters int `json:"chapters"`
Volumes int `json:"volumes"`
Episodes int `json:"episodes"`
} `json:"media"`
} `json:"entries"`
} `json:"lists"`
} `json:"MediaListCollection"`
MediaListCollection ListCollection `json:"MediaListCollection"`
} `json:"data"`
}

Expand All @@ -36,8 +39,6 @@ func parseMediaStatus(status string) string {
return "DROPPED"
case "paused", "ps":
return "PAUSED"
case "repeating", "rp":
return "REPEATING"
default:
return "CURRENT"
}
Expand All @@ -53,9 +54,10 @@ func (ml *MediaList) Get(mediaType string, status string) error {
}

query :=
`query($userId: Int, $type: MediaType, $status: MediaListStatus) {
MediaListCollection(userId: $userId, type: $type, status: $status) {
`query($userId: Int, $type: MediaType, $status: [MediaListStatus]) {
MediaListCollection(userId: $userId, type: $type, status_in: $status) {
lists {
status
entries {
progress
progressVolumes
Expand All @@ -73,12 +75,22 @@ func (ml *MediaList) Get(mediaType string, status string) error {
}
}`

parsedStatus := parseMediaStatus(status)

var parsedStatusSlice []string = make([]string, 0)

if parsedStatus == "CURRENT" {
parsedStatusSlice = append(parsedStatusSlice, parsedStatus, "REPEATING")
} else {
parsedStatusSlice = append(parsedStatusSlice, parsedStatus)
}

err = anilistClient.ExecuteGraqhQL(
query,
map[string]interface{}{
"type": mediaType,
"userId": tokenConfig.UserId,
"status": parseMediaStatus(status),
"status": parsedStatusSlice,
},
&ml,
)
Expand Down
Loading
Loading