diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-13 19:51:47 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-06-13 19:51:47 +0530 |
commit | 5ac21806f34a7c88d2685420d53cbd585f4b4f3d (patch) | |
tree | fa8a1955702a46ba8aaa4d2069551cc8f4433c39 | |
parent | c37e75f4723f745edd54a3dcd57f3ecf2aab4c83 (diff) |
updating episodes now
-rw-r--r-- | cmd/root.go | 20 | ||||
-rw-r--r-- | cmd/search.go | 39 | ||||
-rw-r--r-- | mal/episodes.go | 48 | ||||
-rw-r--r-- | mal/status.go | 4 | ||||
-rw-r--r-- | ui/episodes.go | 83 |
5 files changed, 158 insertions, 36 deletions
diff --git a/cmd/root.go b/cmd/root.go index 9e86905..b9967b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,21 +24,11 @@ import ( "github.com/spf13/cobra" ) -// rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "macli", - Short: "Unofficial CLI-Based MyAnimeList Client.", - Long: `Description to be added later. -Help: - Even I don't know how to use it as of now... -`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Short: "macli - Unofficial CLI-Based MyAnimeList Client.", } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -47,11 +37,5 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.PersistentFlags().BoolP("manga", "m", false, "Use Manga Mode.") } diff --git a/cmd/search.go b/cmd/search.go index 8dff6bf..2496e17 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" "github.com/MikunoNaka/macli/ui" "strings" + "fmt" ) -// searchCmd represents the search command var searchCmd = &cobra.Command { Use: "search", Short: "Search for an anime.", @@ -34,26 +34,31 @@ var searchCmd = &cobra.Command { Run: func(cmd *cobra.Command, args []string) { // read searchInput from command searchInput := strings.Join(args, " ") - // if blank, ask for input - if searchInput == "" { - searchInput = ui.TextInput("Search Anime:", "Search can't be blank.") + mangaMode, _ := cmd.Flags().GetBool("manga") + + if mangaMode { + searchManga(searchInput) + } else { + searchAnime(searchInput) } - animeId := ui.SearchAndGetID("Select Anime", searchInput) - action := ui.ActionMenu() - action(animeId) }, } -func init() { - rootCmd.AddCommand(searchCmd) - - // Here you will define your flags and configuration settings. +func searchManga(searchInput string) { + if searchInput == "" { + searchInput = ui.TextInput("Search Manga:", "Search can't be blank.") + } + fmt.Printf("You typed in \"%s\" but macli doesn't search manga yet.\n", searchInput) +} - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // searchCmd.PersistentFlags().String("foo", "", "A help for foo") +func searchAnime(searchInput string) { + if searchInput == "" { + searchInput = ui.TextInput("Search Anime:", "Search can't be blank.") + } + animeId := ui.SearchAndGetID("Select Anime", searchInput) + ui.ActionMenu()(animeId) +} - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // searchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +func init() { + rootCmd.AddCommand(searchCmd) } diff --git a/mal/episodes.go b/mal/episodes.go new file mode 100644 index 0000000..30fc5d2 --- /dev/null +++ b/mal/episodes.go @@ -0,0 +1,48 @@ +/* +macli - Unofficial CLI-Based MyAnimeList Client +Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package mal + +import ( + "log" + "strconv" +) + +func SetEpisodes(animeId int, ep string) { + epValue, err := strconv.Atoi(ep) + if err != nil { + log.Fatal("Error while parsing episode input", err) + } + + sign := ep[0:1] + if sign == "+" || sign == "-" { + log.Printf("Cannot increment/decrement watched episodes by %d\n. Currently that doesn't wokr", epValue) + return + } + + userAnimeClient.SetWatchedEpisodes(animeId, epValue) +} + +func SetChapters(mangaId int, ch string) { + chValue, err := strconv.Atoi(ch) + if err != nil { + log.Fatal("Error while parsing chapter input", err) + } + + log.Printf("peeepee%s%d", ch[0:1], chValue) +} diff --git a/mal/status.go b/mal/status.go index 1f64bab..06d7773 100644 --- a/mal/status.go +++ b/mal/status.go @@ -24,5 +24,7 @@ import ( func SetStatus(animeId int, status string) { resp, _ := userAnimeClient.SetStatus(animeId, status) - log.Println(resp.Error, resp.Message) + if resp.Error != "" { + log.Println("MyAnimeList reported error on SetStatus", resp.Error, resp.Message) + } } diff --git a/ui/episodes.go b/ui/episodes.go new file mode 100644 index 0000000..a2413bd --- /dev/null +++ b/ui/episodes.go @@ -0,0 +1,83 @@ +/* +macli - Unofficial CLI-Based MyAnimeList Client +Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package ui + +import ( + "strconv" + "log" + "github.com/MikunoNaka/macli/mal" + p "github.com/manifoldco/promptui" +) + +func EpisodeInput(animeId int) { + validate := func(input string) error { + _, err := strconv.ParseFloat(input, 64) + return err + } + + template := &p.PromptTemplates { + Prompt: "{{ . }} ", + Valid: "{{ . }} ", + Invalid: "{{ . | red }} ", + Success: "{{ . }} ", + } + + prompt := p.Prompt { + // Label: "Set Episode Number: (Increment/Decrement With +1, -2, etc)", + Label: "Set Episode Number: ", + Templates: template, + Validate: validate, + } + + res, err := prompt.Run() + if err != nil { + log.Println("Error Running EpisodeInput Prompt.", err) + return + } + + mal.SetEpisodes(animeId, res) +} + +func ChapterInput(mangaId int) { + validate := func(input string) error { + _, err := strconv.ParseFloat(input, 64) + return err + } + + template := &p.PromptTemplates { + Prompt: "{{ . }} ", + Valid: "{{ . }} ", + Invalid: "{{ . | red }} ", + Success: "{{ . }} ", + } + + prompt := p.Prompt { + Label: "Set Chapter Number: (Increment/Decrement With +1, -2, etc)", + Templates: template, + Validate: validate, + } + + res, err := prompt.Run() + if err != nil { + log.Println("Error Running ChapterInput Prompt.", err) + return + } + + mal.SetChapters(mangaId, res) +} |