diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 15:28:27 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 15:28:27 +0530 |
commit | e1bd26b9ad73cd0758ba77373c1cd07f72f47a65 (patch) | |
tree | bfcba01cdf2b5e0d3f659b097d3683eb83fb89d0 /cmd | |
parent | d67758bdbeb162adadb6b19954e8e22cf04ed388 (diff) |
reading both flags and config for list commands
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/list.go | 29 | ||||
-rw-r--r-- | cmd/seasonals.go | 24 |
2 files changed, 29 insertions, 24 deletions
diff --git a/cmd/list.go b/cmd/list.go index e4dbcf1..9cc0559 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -22,11 +22,10 @@ import ( "os" "fmt" "github.com/MikunoNaka/macli/ui" + "github.com/MikunoNaka/macli/util" "github.com/MikunoNaka/macli/mal" - // m "github.com/MikunoNaka/MAL2Go/v4/manga" "github.com/spf13/cobra" - "github.com/spf13/viper" ) // statusCmd represents the status command @@ -41,6 +40,14 @@ var listCmd = &cobra.Command{ // " - \x1b[33m`macli chapters -s +1 <anime-name>`\x1b[0m to increment the chapters by 1\n" + // " - \x1b[33m`macli chapters -s -2 <anime-name>`\x1b[0m to decrement the chapters by 2\n", Run: func(cmd *cobra.Command, args []string) { + conf, err := util.BindListConfig(cmd.Flags()) + if err != nil { + fmt.Println("Error while parsing flags.", err.Error()) + os.Exit(1) + } + mal.SearchLength = conf.ResultsLength + mal.SearchOffset = conf.ResultsOffset + mal.SearchNSFW = conf.IncludeNSFW mal.Init() status, err := cmd.Flags().GetString("status") @@ -61,16 +68,10 @@ var listCmd = &cobra.Command{ os.Exit(1) } - nsfw, err := cmd.Flags().GetBool("include-nsfw") - if err != nil { - fmt.Println("error while reading \x1b[33m--include-nsfw\x1b[0m flag:", err) - os.Exit(1) - } - if mangaMode { - ui.MangaList(mal.MangaList(user, status, sort, nsfw)) + ui.MangaList(mal.MangaList(user, status, sort, conf.IncludeNSFW)) } else { - ui.AnimeList(mal.AnimeList(user, status, sort, nsfw)) + ui.AnimeList(mal.AnimeList(user, status, sort, conf.IncludeNSFW)) } }, @@ -81,13 +82,11 @@ func init() { listCmd.Flags().StringP("status", "", "", "Status (leave blank for all)") listCmd.Flags().StringP("user", "", "@me", "User (@me or blank for self)") listCmd.Flags().StringP("sort", "", "list_score", "Sort the list") - listCmd.Flags().BoolP("include-nsfw", "", false, "Include NSFW results") listCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode") listCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") listCmd.Flags().IntVarP(&mal.SearchLength, "list-length", "n", 15, "Amount of list items to load (default: all)") - listCmd.Flags().IntVarP(&mal.SearchOffset, "list-offset", "o", 0, "Offset for the list") - viper.BindPFlag("lists.list_offset", listCmd.Flags().Lookup("list-offset")) - viper.BindPFlag("lists.list_length", listCmd.Flags().Lookup("list-length")) - viper.BindPFlag("lists.include_nsfw_results", listCmd.Flags().Lookup("include-nsfw")) + listCmd.Flags().IntP("results-length", "n", 10, "Amount of results to load") + listCmd.Flags().IntP("results-offset", "o", 0, "Offset for the results") + listCmd.Flags().BoolP("include-nsfw", "", false, "Include NSFW-rated items in search results") } diff --git a/cmd/seasonals.go b/cmd/seasonals.go index b78876a..3ea5012 100644 --- a/cmd/seasonals.go +++ b/cmd/seasonals.go @@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. package cmd import ( - // "os" + "os" "fmt" // "strings" // "github.com/MikunoNaka/macli/ui" @@ -33,13 +33,22 @@ import ( // statusCmd represents the status command var seasonalsCmd = &cobra.Command{ Use: "seasonals", - Short: "Get seasonal animes", - Long: "" + + Short: "Get seasonal animes (under construction)", + Long: "under construction" + "" + "", Run: func(cmd *cobra.Command, args []string) { + conf, err := util.BindListConfig(cmd.Flags()) + if err != nil { + fmt.Println("Error while parsing flags.", err.Error()) + os.Exit(1) + } + mal.SearchLength = conf.ResultsLength + mal.SearchOffset = conf.ResultsOffset + mal.SearchNSFW = conf.IncludeNSFW mal.Init() + season := util.GetCurrentSeason() sort, _ := cmd.Flags().GetString("sort") @@ -59,15 +68,12 @@ var seasonalsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(seasonalsCmd) - seasonalsCmd.Flags().IntVarP(&mal.SearchLength, "results-length", "n", 15, "Amount of results to load") - seasonalsCmd.Flags().BoolVarP(&mal.SearchNSFW, "include-nsfw", "", false, "Include NSFW-rated items in results") - seasonalsCmd.Flags().IntVarP(&mal.SearchOffset, "results-offset", "o", 0, "Offset for the results") seasonalsCmd.Flags().StringP("sort", "", "anime_num_list_users", "sort") seasonalsCmd.Flags().StringP("season", "", "", "") seasonalsCmd.Flags().IntP("year", "", 0, "") seasonalsCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") - viper.BindPFlag("lists.list_length", seasonalsCmd.Flags().Lookup("results-length")) - viper.BindPFlag("lists.list_offset", seasonalsCmd.Flags().Lookup("results-offset")) - viper.BindPFlag("lists.include_nsfw_results", seasonalsCmd.Flags().Lookup("include-nsfw")) + seasonalsCmd.Flags().IntP("results-length", "n", 10, "Amount of results to load") + seasonalsCmd.Flags().IntP("results-offset", "o", 0, "Offset for the results") + seasonalsCmd.Flags().BoolP("include-nsfw", "", false, "Include NSFW-rated items in search results") } |