From adffba663dbe8daebe311dc8f3ae5d40109cb2dd Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 17 Aug 2022 22:33:40 +0530 Subject: reading config file's defaults while searching --- cmd/chapters.go | 8 ++++---- cmd/episodes.go | 8 ++++---- cmd/list.go | 5 ++++- cmd/login.go | 6 +++--- cmd/root.go | 24 ++++++++++-------------- cmd/score.go | 8 ++++---- cmd/search.go | 9 +++++---- cmd/seasonals.go | 4 +--- cmd/status.go | 1 + 9 files changed, 36 insertions(+), 37 deletions(-) (limited to 'cmd') diff --git a/cmd/chapters.go b/cmd/chapters.go index 2728beb..4e5be08 100644 --- a/cmd/chapters.go +++ b/cmd/chapters.go @@ -92,10 +92,10 @@ var chaptersCmd = &cobra.Command{ func init() { rootCmd.AddCommand(chaptersCmd) chaptersCmd.Flags().StringP("set-value", "s", "", "Number of chapters") - chaptersCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") - chaptersCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") - chaptersCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") - chaptersCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") + chaptersCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", promptLength, "Length of select prompt") + chaptersCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", searchLength, "Amount of search results to load") + chaptersCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", searchOffset, "Offset for the search results") + chaptersCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", searchNsfw, "Include NSFW-rated items in search results") chaptersCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") chaptersCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") chaptersCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") diff --git a/cmd/episodes.go b/cmd/episodes.go index e760eff..0423679 100644 --- a/cmd/episodes.go +++ b/cmd/episodes.go @@ -92,11 +92,11 @@ var episodesCmd = &cobra.Command{ func init() { rootCmd.AddCommand(episodesCmd) episodesCmd.Flags().StringP("set-value", "s", "", "Number of episodes") - episodesCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") + episodesCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", promptLength, "Length of select prompt") episodesCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") - episodesCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") - episodesCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") - episodesCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") + episodesCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", searchLength, "Amount of search results to load") + episodesCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", searchNsfw, "Include NSFW-rated items in search results") + episodesCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", searchOffset, "Offset for the search results") episodesCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") episodesCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") } diff --git a/cmd/list.go b/cmd/list.go index 2b9cc57..6cb95fb 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -80,7 +80,10 @@ 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().BoolP("include-nsfw", "", listIncludeNsfw, "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)") + // TODO: implement below 2 flags + // listCmd.Flags().IntVarP(&mal.SearchLength, "list-length", "n", listLength, "Amount of list items to load (default: all)") + // listCmd.Flags().IntVarP(&mal.SearchOffset, "list-offset", "o", listOffset, "Offset for the list") } diff --git a/cmd/login.go b/cmd/login.go index 71e4b5a..7127c47 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -19,8 +19,8 @@ along with this program. If not, see . package cmd import ( - "fmt" "os" + "fmt" "github.com/spf13/cobra" "github.com/MikunoNaka/macli/auth" ) @@ -61,8 +61,8 @@ var loginCmd = &cobra.Command { } func init() { - rootCmd.AddCommand(loginCmd) + rootCmd.AddCommand(loginCmd) loginCmd.Flags().StringP("authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") loginCmd.Flags().StringP("client-id", "c", "", "MyAnimeList Client ID") - loginCmd.Flags().StringP("store-client-id", "s", "yes", "Save Client ID to keyring (yes/no) (Default: yes)") + loginCmd.Flags().StringP("store-client-id", "s", saveClientId, "Save Client ID to keyring (yes/no) (Default: yes)") } diff --git a/cmd/root.go b/cmd/root.go index 1b956cf..02d27a1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,22 +29,24 @@ import ( var ( queryOnlyMode, mangaMode bool entryId int - authConfig, defConfig map[string]interface{} - // config vars - /* TODO: load config vars here - * then set config file's values or default values - * conditionally after loading the config file - */ + // auth + saveClientId string = "yes" + // searching + promptLength, searchLength, searchOffset int = 5, 10, 0 + searchNsfw bool = false + // lists + listOffset, listLength int = 0, 15 + listIncludeNsfw bool = false ) var rootCmd = &cobra.Command{ - Use: "macli", + Use: "macli", Short: "macli - Unofficial CLI-Based MyAnimeList Client.", Long: "macli is an unofficial MyAnimeList Client for use inside the terminal.", } -func init() { +func Execute() { viper.SetConfigName("macli") viper.SetConfigType("yaml") viper.AddConfigPath(".") @@ -62,12 +64,6 @@ func init() { } } - // load config file contents - authConfig = viper.Get("auth").(map[string]interface{}) - defConfig = viper.Get("defaults").(map[string]interface{}) -} - -func Execute() { err := rootCmd.Execute() if err != nil { os.Exit(1) diff --git a/cmd/score.go b/cmd/score.go index 6a2df9c..ec26252 100644 --- a/cmd/score.go +++ b/cmd/score.go @@ -159,10 +159,10 @@ func setMangaScore(scoreInput, searchInput string) { func init() { rootCmd.AddCommand(scoreCmd) scoreCmd.Flags().StringP("set-value", "s", "", "Score to be set") - scoreCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") - scoreCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") - scoreCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") - scoreCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") + scoreCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", promptLength, "Length of select prompt") + scoreCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", searchLength, "Amount of search results to load") + scoreCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", searchOffset, "Offset for the search results") + scoreCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", searchNsfw, "Include NSFW-rated items in search results") scoreCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode") scoreCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") scoreCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") diff --git a/cmd/search.go b/cmd/search.go index b6aaf3e..76babf4 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -113,12 +113,13 @@ func searchAnime(searchInput string) { } func init() { + fmt.Println("searchInit") rootCmd.AddCommand(searchCmd) - searchCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") + searchCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", promptLength, "Length of select prompt") searchCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode") - searchCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") - 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().IntVarP(&mal.SearchLength, "search-length", "n", searchLength, "Amount of search results to load") + searchCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", searchOffset, "Offset for the search results") + searchCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", searchNsfw, "Include NSFW-rated items in search results") searchCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of anime/manga (overrides search)") searchCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") searchCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") diff --git a/cmd/seasonals.go b/cmd/seasonals.go index 7fd4cde..5efe544 100644 --- a/cmd/seasonals.go +++ b/cmd/seasonals.go @@ -22,7 +22,7 @@ import ( // "os" "fmt" // "strings" - "github.com/MikunoNaka/macli/ui" + // "github.com/MikunoNaka/macli/ui" "github.com/MikunoNaka/macli/util" "github.com/MikunoNaka/macli/mal" @@ -58,8 +58,6 @@ var seasonalsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(seasonalsCmd) - seasonalsCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") - seasonalsCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") seasonalsCmd.Flags().IntVarP(&mal.SearchLength, "results-length", "n", 10, "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") diff --git a/cmd/status.go b/cmd/status.go index 2dc6fee..53e93c6 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -133,6 +133,7 @@ func setMangaStatus(statusInput, searchInput string) { } func init() { + fmt.Println("statusINit") rootCmd.AddCommand(statusCmd) statusCmd.Flags().StringP("set-value", "s", "", "status to be set") statusCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") -- cgit v1.2.3