aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-04 21:09:54 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-04 21:09:54 +0530
commita8c3e33462bc295bd727e39364cfd26e4aa4ea4d (patch)
treeb8caaaac4a661cca819270b5d88b997ea4572c19 /cmd
parent4879f9849d224849cd9118a68f079bbd917b2b14 (diff)
added --id flag to search and status commands
Diffstat (limited to 'cmd')
-rw-r--r--cmd/root.go4
-rw-r--r--cmd/search.go13
-rw-r--r--cmd/status.go43
-rw-r--r--cmd/version.go2
4 files changed, 42 insertions, 20 deletions
diff --git a/cmd/root.go b/cmd/root.go
index c1e939c..f1fba18 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -41,7 +41,3 @@ func Execute() {
os.Exit(1)
}
}
-
-func init() {
- rootCmd.PersistentFlags().IntVar(&entryId, "id", -1, "Manually specify the ID of anime/manga (overrides search)")
-}
diff --git a/cmd/search.go b/cmd/search.go
index 92a1b24..0c166b2 100644
--- a/cmd/search.go
+++ b/cmd/search.go
@@ -56,6 +56,12 @@ var searchCmd = &cobra.Command {
}
func searchManga(searchInput string) {
+ if entryId > 0 {
+ selectedManga := mal.GetMangaData(entryId, []string{"my_list_status", "title"})
+ fmt.Println("Selected: \x1b[35m" + selectedManga.Title + "\x1b[0m")
+ ui.MangaActionMenu(selectedManga.MyListStatus.Status != "")(selectedManga)
+ os.Exit(0)
+ }
if searchInput == "" {
searchInput = ui.TextInput("Search Manga: ", "Search can't be blank.")
}
@@ -66,6 +72,12 @@ func searchManga(searchInput string) {
}
func searchAnime(searchInput string) {
+ if entryId > 0 {
+ selectedAnime := mal.GetAnimeData(entryId, []string{"my_list_status"})
+ fmt.Println("Selected: \x1b[35m" + selectedAnime.Title + "\x1b[0m")
+ ui.AnimeActionMenu(selectedAnime.MyListStatus.Status != "")(selectedAnime)
+ os.Exit(0)
+ }
if searchInput == "" {
searchInput = ui.TextInput("Search Anime: ", "Search can't be blank.")
}
@@ -83,4 +95,5 @@ func init() {
searchCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results")
searchCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results")
searchCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)")
+ searchCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)")
}
diff --git a/cmd/status.go b/cmd/status.go
index 540d84e..ba5d047 100644
--- a/cmd/status.go
+++ b/cmd/status.go
@@ -24,6 +24,8 @@ import (
"strings"
"github.com/MikunoNaka/macli/ui"
"github.com/MikunoNaka/macli/mal"
+ a "github.com/MikunoNaka/MAL2Go/v3/anime"
+ m "github.com/MikunoNaka/MAL2Go/v3/manga"
"github.com/spf13/cobra"
)
@@ -63,7 +65,12 @@ var statusCmd = &cobra.Command{
}
func setAnimeStatus(statusInput, searchInput string) {
- if searchInput == "" {
+ var selectedAnime a.Anime
+ if entryId > 0 {
+ selectedAnime = mal.GetAnimeData(entryId, []string{"my_list_status"})
+ }
+
+ if searchInput == "" && entryId < 1 {
var promptText string
if queryOnlyMode {
promptText = "Search Anime to Get Status of: "
@@ -73,26 +80,31 @@ func setAnimeStatus(statusInput, searchInput string) {
searchInput = ui.TextInput(promptText, "Search can't be blank.")
}
- anime := ui.AnimeSearch("Select Anime:", searchInput)
- selectedAnime := mal.GetAnimeData(anime.Id, []string{"my_list_status"})
+ if entryId < 1 {
+ anime := ui.AnimeSearch("Select Anime:", searchInput)
+ selectedAnime = mal.GetAnimeData(anime.Id, []string{"my_list_status"})
+ }
if queryOnlyMode {
- status := selectedAnime.MyListStatus.Status
- // fmt.Printf("Anime: \x1b[35m%s\x1b[0m, Status: %s%s\x1b[0m\n", anime.Title, ui.GetColorCodeByStatus(status), ui.FormatStatus(status))
- fmt.Printf("\x1b[35m%s\x1b[0m :: %s%s\x1b[0m\n", anime.Title, ui.GetColorCodeByStatus(status), ui.FormatStatus(status))
+ fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedAnime.Title, selectedAnime.MyListStatus.Status, ""))
os.Exit(0)
}
if statusInput == "" {
ui.AnimeStatusMenu(selectedAnime)
} else {
- resp := mal.SetAnimeStatus(anime.Id, statusInput)
- fmt.Println(ui.CreateStatusUpdateConfirmationMessage(anime.Title, resp.Status))
+ resp := mal.SetAnimeStatus(selectedAnime.Id, statusInput)
+ fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedAnime.Title, resp.Status, selectedAnime.MyListStatus.Status))
}
}
func setMangaStatus(statusInput, searchInput string) {
- if searchInput == "" {
+ var selectedManga m.Manga
+ if entryId > 0 {
+ selectedManga = mal.GetMangaData(entryId, []string{"my_list_status"})
+ }
+
+ if searchInput == "" && entryId < 1 {
var promptText string
if queryOnlyMode {
promptText = "Search Manga to Get Status of: "
@@ -102,13 +114,13 @@ func setMangaStatus(statusInput, searchInput string) {
searchInput = ui.TextInput(promptText, "Search can't be blank.")
}
- manga := ui.MangaSearch("Select Manga:", searchInput)
- selectedManga := mal.GetMangaData(manga.Id, []string{"my_list_status"})
+ if entryId < 1 {
+ manga := ui.MangaSearch("Select Manga:", searchInput)
+ selectedManga = mal.GetMangaData(manga.Id, []string{"my_list_status"})
+ }
if queryOnlyMode {
- status := selectedManga.MyListStatus.Status
- // fmt.Printf("Manga: \x1b[35m%s\x1b[0m, Status: %s%s\x1b[0m\n", manga.Title, ui.GetColorCodeByStatus(status), ui.FormatStatus(status))
- fmt.Printf("\x1b[35m%s\x1b[0m :: %s%s\x1b[0m\n", manga.Title, ui.GetColorCodeByStatus(status), ui.FormatStatus(status))
+ fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedManga.Title, selectedManga.MyListStatus.Status, ""))
os.Exit(0)
}
@@ -117,7 +129,7 @@ func setMangaStatus(statusInput, searchInput string) {
} else {
resp := mal.SetMangaStatus(selectedManga.Id, statusInput)
fmt.Println(resp.Status)
- fmt.Println(ui.CreateStatusUpdateConfirmationMessage(manga.Title, resp.Status))
+ fmt.Println(ui.CreateStatusUpdateConfirmationMessage(selectedManga.Title, resp.Status, selectedManga.MyListStatus.Status))
}
}
@@ -130,4 +142,5 @@ func init() {
statusCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results")
statusCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode")
statusCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)")
+ statusCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)")
}
diff --git a/cmd/version.go b/cmd/version.go
index ddca5e4..2721e89 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra"
)
-var version string = "v1.7.2"
+const version string = "v1.7.2"
var versionCmd = &cobra.Command {
Use: "version",