aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/chapters.go33
-rw-r--r--cmd/episodes.go33
-rw-r--r--cmd/root.go6
-rw-r--r--cmd/search.go8
-rw-r--r--cmd/status.go7
-rw-r--r--ui/episodes.go16
6 files changed, 75 insertions, 28 deletions
diff --git a/cmd/chapters.go b/cmd/chapters.go
index c28bb8f..87cdd19 100644
--- a/cmd/chapters.go
+++ b/cmd/chapters.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 chaptersCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
searchInput := strings.Join(args, " ")
if searchInput == "" {
- searchInput = ui.TextInput("Search Manga To Set Chapters For: ", "Search can't be blank.")
+ var promptText string
+ if queryOnlyMode {
+ promptText = "Search Manga to Get Amount of Chapters Read For: "
+ } else {
+ promptText = "Search Manga to Set Chapters For: "
+ }
+ searchInput = ui.TextInput(promptText, "Search can't be blank.")
}
- chInput, err := cmd.Flags().GetString("set-value")
- if err != nil {
- fmt.Println("Error while reading --set-value flag.", err.Error())
+ var (
+ chInput string
+ err error
+ )
+ if !queryOnlyMode {
+ chInput, 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)
+ }
}
manga := ui.MangaSearch("Select Manga:", searchInput)
- mangaData := mal.GetMangaData(manga.Id, []string{"my_list_status"})
- prevChRead := mangaData.MyListStatus.ChaptersRead
+ selectedManga := mal.GetMangaData(manga.Id, []string{"my_list_status", "num_chapters"})
+ prevChRead := selectedManga.MyListStatus.ChaptersRead
+
+ if queryOnlyMode {
+ fmt.Printf("You Have read \x1b[1;36m%d\x1b[0m out of \x1b[1;33m%d\x1b[0m chapters from \x1b[35m%s\x1b[0m\n", prevChRead, selectedManga.NumChapters, manga.Title)
+ os.Exit(0)
+ }
if chInput == "" {
- ui.ChapterInput(manga)
+ ui.ChapterInput(selectedManga)
} else {
resp := mal.SetChapters(manga.Id, prevChRead, chInput)
fmt.Println(ui.CreateChapterUpdateConfirmationMessage(manga.Title, prevChRead, resp.ChaptersRead))
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))
diff --git a/cmd/root.go b/cmd/root.go
index 2ac48d6..085dafa 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -24,6 +24,9 @@ import (
"github.com/spf13/cobra"
)
+var queryOnlyMode bool
+var mangaMode bool
+
var rootCmd = &cobra.Command{
Use: "macli",
Short: "macli - Unofficial CLI-Based MyAnimeList Client.",
@@ -48,5 +51,6 @@ func Execute() {
}
func init() {
- rootCmd.PersistentFlags().BoolP("manga", "m", false, "use manga mode")
+ rootCmd.PersistentFlags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode")
+ rootCmd.PersistentFlags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)")
}
diff --git a/cmd/search.go b/cmd/search.go
index 2e485e3..89ab17f 100644
--- a/cmd/search.go
+++ b/cmd/search.go
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
+ "os"
+ "fmt"
"strings"
"github.com/spf13/cobra"
"github.com/MikunoNaka/macli/ui"
@@ -36,7 +38,11 @@ var searchCmd = &cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
// read searchInput from command
searchInput := strings.Join(args, " ")
- mangaMode, _ := cmd.Flags().GetBool("manga")
+ mangaMode, err := cmd.Flags().GetBool("manga")
+ if err != nil {
+ fmt.Println("Error while reading \x1b[33m--manga\x1b[0m flag.", err.Error())
+ os.Exit(1)
+ }
if mangaMode {
searchManga(searchInput)
diff --git a/cmd/status.go b/cmd/status.go
index 662ebf2..bd4307e 100644
--- a/cmd/status.go
+++ b/cmd/status.go
@@ -20,6 +20,7 @@ package cmd
import (
"fmt"
+ "os"
"strings"
"github.com/MikunoNaka/macli/ui"
"github.com/MikunoNaka/macli/mal"
@@ -41,12 +42,14 @@ var statusCmd = &cobra.Command{
statusInput, err := cmd.Flags().GetString("set-value")
if err != nil {
- fmt.Println("Error while reading status flag.", err.Error())
+ fmt.Println("Error while reading \x1b[33m--set-value\x1b[0m flag.", err.Error())
+ os.Exit(1)
}
mangaMode, err := cmd.Flags().GetBool("manga")
if err != nil {
- fmt.Println("Error while reading manga flag.", err.Error())
+ fmt.Println("Error while reading \x1b[33m--manga\x1b[0m flag.", err.Error())
+ os.Exit(1)
}
if mangaMode {
diff --git a/ui/episodes.go b/ui/episodes.go
index edf05a4..8b1bcff 100644
--- a/ui/episodes.go
+++ b/ui/episodes.go
@@ -39,10 +39,8 @@ func CreateChapterUpdateConfirmationMessage(title string, prevChNum, chNum int)
}
func EpisodeInput(anime a.Anime) {
- // fetch number of total episodes, number of watched episodes from the API
- animeData := mal.GetAnimeData(anime.Id, []string{"num_episodes", "my_list_status"})
- epWatchedNum := animeData.MyListStatus.EpWatched
- epTotalNum := animeData.NumEpisodes
+ epWatchedNum := anime.MyListStatus.EpWatched
+ epTotalNum := anime.NumEpisodes
validate := func(input string) error {
if _, err := strconv.ParseFloat(input, 64); err != nil {
@@ -74,10 +72,8 @@ func EpisodeInput(anime a.Anime) {
}
func ChapterInput(manga m.Manga) {
- // fetch number of total chapters, number of read chapters from the API
- animeData := mal.GetMangaData(manga.Id, []string{"num_chapters", "my_list_status"})
- chReadNum := animeData.MyListStatus.ChaptersRead
- chTotalNum := animeData.NumChapters
+ chReadNum := manga.MyListStatus.ChaptersRead
+ chTotalNum := manga.NumChapters
validate := func(input string) error {
if _, err := strconv.ParseFloat(input, 64); err != nil {
@@ -104,6 +100,6 @@ func ChapterInput(manga m.Manga) {
os.Exit(1)
}
- // TODO: read resp and show confirmation message
- mal.SetChapters(manga.Id, chReadNum, res)
+ resp := mal.SetChapters(manga.Id, chReadNum, res)
+ fmt.Println(CreateChapterUpdateConfirmationMessage(manga.Title, chReadNum, resp.ChaptersRead))
}