Skip to content

Commit dc8c969

Browse files
Merge pull request #36 from aaravmaloo/main
Add structured JSON output and expanded title metadata (concerns #35)
2 parents 95c0226 + ffdef05 commit dc8c969

21 files changed

Lines changed: 283 additions & 31 deletions

cmd/cmd_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13-
func handleMediaInfo(_ *cobra.Command, args []string) {
13+
func handleMediaInfo(cmd *cobra.Command, args []string) {
1414
id, err := strconv.Atoi(args[0])
1515
if err != nil {
1616
fmt.Println(ui.ErrorText(errors.New("invalid media id provided")))
1717
}
1818

19-
err = viewmodel.HandleMediaInfo(id)
19+
err = viewmodel.HandleMediaInfo(id, GlobalJSON)
2020
if err != nil {
2121
fmt.Println(ui.ErrorText(err))
2222
}

cmd/cmd_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var listMediaType string
1212
var listStatus string
1313

1414
func handleLs(cmd *cobra.Command, args []string) {
15-
err := viewmodel.HandleMediaList(listMediaType, listStatus)
15+
err := viewmodel.HandleMediaList(listMediaType, listStatus, GlobalJSON)
1616
if err != nil {
1717
fmt.Println(ui.ErrorText(err))
1818
}

cmd/cmd_media_search.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ func handleMediaSearch(cmd *cobra.Command, args []string) {
1919
os.Exit(0)
2020
}
2121

22-
combinedQuery := strings.Join(args, "")
22+
combinedQuery := strings.Join(args, " ")
2323
err := viewmodel.HandleMediaSearch(
2424
combinedQuery,
2525
searchMediaType,
2626
pageSize,
27+
GlobalJSON,
2728
)
2829

2930
if err != nil {

cmd/cmd_profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func handleProfile(cmd *cobra.Command, args []string) {
12-
err := viewmodel.HandleProfile()
12+
err := viewmodel.HandleProfile(GlobalJSON)
1313
if err != nil {
1414
fmt.Println(ui.ErrorText(err))
1515
}

cmd/cmd_root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13+
var GlobalJSON bool
14+
1315
var rootCmd = &cobra.Command{
1416
Use: "chibi",
1517
Long: "Chibi for AniList - A lightweight anime & manga tracker CLI app powered by AniList.\nRead the documentation at https://chibi-cli.pages.dev/",
@@ -34,6 +36,7 @@ func Execute(version string) {
3436
mediaInfoCmd,
3537
themeCmd,
3638
)
39+
rootCmd.PersistentFlags().BoolVarP(&GlobalJSON, "json", "j", false, "Output in JSON format")
3740
if err := fang.Execute(
3841
context.TODO(),
3942
rootCmd,

docs/02_cli_guide/info.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Info
3+
lang: en-US
4+
---
5+
6+
# The `info` Command
7+
8+
The `chibi info` command provides detailed information about a specific anime or manga using its AniList ID.
9+
10+
## Usage
11+
```bash
12+
$ chibi info [id] [flags]
13+
```
14+
15+
## Flags
16+
17+
### `-h, --help`
18+
Provides help information for the `chibi info` command.
19+
20+
### `-j, --json`
21+
Outputs the media information in a structured JSON format. This includes IDs, titles (romaji, english, native), synonyms, scores, progress, and full descriptions.
22+
23+
#### Example:
24+
```bash
25+
$ chibi info 21 --json
26+
```
27+
28+
## Output
29+
By default, the command displays a formatted list of metadata, including:
30+
- ID and MAL ID
31+
- Titles (English, Romaji, Native)
32+
- Format (TV, Movie, Manga, etc.)
33+
- Average Score
34+
- Episode/Chapter count
35+
- Genres and Tags
36+
- Studios
37+
- Detailed Description

docs/02_cli_guide/ls.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ chibi list --status watching --type anime
6363

6464
This command will display a list of anime that you are currently watching.
6565

66+
### `-j, --json`
67+
Outputs the list in a structured JSON format. This is particularly useful for automation scripts and programmatic data processing.
68+
69+
The JSON output includes:
70+
- `id`: The AniList Media ID
71+
- `status`: The current status (e.g., WATCHING, COMPLETED)
72+
- `progress`: Your current episode or chapter progress
73+
- `titles`: A nested object containing `romaji`, `english`, and `native` titles
74+
75+
#### Example:
76+
```bash
77+
$ chibi list --json
78+
```
79+
6680
## Defaults
6781
- The default `status` is `watching`.
6882
- The default `type` is `anime`.

docs/02_cli_guide/profile.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ Provides help information for the `chibi profile` command. Use this flag to disp
2222
$ chibi profile --help
2323
```
2424

25+
### `-j, --json`
26+
Outputs your profile information in a structured JSON format.
27+
28+
The JSON output includes:
29+
- `id`: Your AniList user ID
30+
- `name`: Your username
31+
- `totalAnime`: Your total anime count
32+
- `totalManga`: Your total manga count
33+
- `minutesWatched`: Your total minutes watched
34+
- `chaptersRead`: Your total chapters read
35+
- `avatarUrl`: The URL to your profile avatar
36+
- `siteUrl`: The URL to your AniList profile page
37+
38+
#### Example:
39+
```bash
40+
$ chibi profile --json
41+
```
42+
2543
## Requirements
2644
This command requires you to be logged in to your AniList account. If you are not logged in, the command will prompt you to do so before retrieving your profile information.
2745

docs/02_cli_guide/search.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ $ chibi search "Naruto" --type anime --page 3
5353
```
5454
This command will return up to 3 anime results for the query `"Naruto"`.
5555

56+
### `-j, --json`
57+
Outputs search results in a structured JSON format.
58+
59+
The JSON output includes:
60+
- `id`: The AniList Media ID
61+
- `titles`: A nested object containing `romaji`, `english`, and `native` titles
62+
63+
#### Example:
64+
```bash
65+
$ chibi search "One Piece" --json
66+
```
67+
5668
## Defaults
5769
- The default `type` is `anime`.
5870
- The default `page` is 10 results.

internal/api/queries.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const searchMediaQuery = `query($searchQuery: String, $perPage: Int, $mediaType:
66
id
77
title {
88
userPreferred
9+
romaji
10+
english
11+
native
912
}
1013
type
1114
averageScore
@@ -24,6 +27,9 @@ const mediaListQuery = `query ($id: Int, $statusIn: [MediaListStatus]) {
2427
id
2528
title {
2629
userPreferred
30+
romaji
31+
english
32+
native
2733
}
2834
episodes
2935
chapters
@@ -45,6 +51,9 @@ const mediaListQuery = `query ($id: Int, $statusIn: [MediaListStatus]) {
4551
id
4652
title {
4753
userPreferred
54+
romaji
55+
english
56+
native
4857
}
4958
episodes
5059
chapters
@@ -85,6 +94,7 @@ const mediaInfoQuery = `query($id: Int) {
8594
romaji
8695
native
8796
}
97+
synonyms
8898
meanScore
8999
coverImage {
90100
extraLarge

0 commit comments

Comments
 (0)