From d67758bdbeb162adadb6b19954e8e22cf04ed388 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 30 Sep 2022 15:10:58 +0530 Subject: reading both flags and config for searching commands --- cmd/score.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'cmd/score.go') diff --git a/cmd/score.go b/cmd/score.go index ec26252..a7a5aaa 100644 --- a/cmd/score.go +++ b/cmd/score.go @@ -43,7 +43,17 @@ var scoreCmd = &cobra.Command{ " - \x1b[33m`macli status `\x1b[0m For interactive prompt (anime-name can be omitted)\n" + " - \x1b[33m`macli status -s \x1b[34mwatching|plan_to_watch|dropped|on_hold|completed\x1b[33m `\x1b[0m to specify status from command\n", Run: func(cmd *cobra.Command, args []string) { + conf, err := util.BindSearchConfig(cmd.Flags()) + if err != nil { + fmt.Println("Error while parsing flags.", err.Error()) + os.Exit(1) + } + mal.SearchLength = conf.SearchLength + mal.SearchOffset = conf.SearchOffset + mal.SearchNSFW = conf.SearchNSFW + ui.PromptLength = conf.PromptLength mal.Init() + searchInput := strings.Join(args, " ") scoreInput, err := cmd.Flags().GetString("set-value") @@ -159,12 +169,13 @@ 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", 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)") scoreCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") + + scoreCmd.Flags().IntP("prompt-length", "l", 5, "Length of select prompt") + scoreCmd.Flags().IntP("search-length", "n", 10, "Amount of search results to load") + scoreCmd.Flags().IntP("search-offset", "o", 0, "Offset for the search results") + scoreCmd.Flags().BoolP("search-nsfw", "", false, "Include NSFW-rated items in search results") } -- cgit v1.2.3