diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 15:10:58 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 15:10:58 +0530 |
commit | d67758bdbeb162adadb6b19954e8e22cf04ed388 (patch) | |
tree | 1438369c1d980ebb041a04264da6d9006473e967 /cmd/volumes.go | |
parent | 37b5c5457d51b50af1dcadaf7c85be7e7349d682 (diff) |
reading both flags and config for searching commands
Diffstat (limited to 'cmd/volumes.go')
-rw-r--r-- | cmd/volumes.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/cmd/volumes.go b/cmd/volumes.go index 92b588b..6df1b69 100644 --- a/cmd/volumes.go +++ b/cmd/volumes.go @@ -23,6 +23,7 @@ import ( "fmt" "strings" "github.com/MikunoNaka/macli/ui" + "github.com/MikunoNaka/macli/util" "github.com/MikunoNaka/macli/mal" m "github.com/MikunoNaka/MAL2Go/v4/manga" @@ -41,7 +42,17 @@ var volumesCmd = &cobra.Command{ " - \x1b[33m`macli volumes -s +1 <manga-name>`\x1b[0m to increment the volumes by 1\n" + " - \x1b[33m`macli volumes -s -2 <manga-name>`\x1b[0m to decrement the volumes by 2\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() + var selectedManga m.Manga if entryId > 0 { selectedManga = mal.GetMangaData(entryId, []string{"my_list_status", "num_volumes"}) @@ -58,10 +69,7 @@ var volumesCmd = &cobra.Command{ searchInput = ui.TextInput(promptText, "Search can't be blank.") } - var ( - volInput string - err error - ) + var volInput string if !queryOnlyMode { volInput, err = cmd.Flags().GetString("set-value") if err != nil { @@ -92,11 +100,12 @@ var volumesCmd = &cobra.Command{ func init() { rootCmd.AddCommand(volumesCmd) volumesCmd.Flags().StringP("set-value", "s", "", "Number of voulmes") - volumesCmd.Flags().IntVarP(&ui.PromptLength, "prompt-length", "l", 5, "Length of select prompt") - volumesCmd.Flags().IntVarP(&mal.SearchLength, "search-length", "n", 10, "Amount of search results to load") - volumesCmd.Flags().IntVarP(&mal.SearchOffset, "search-offset", "o", 0, "Offset for the search results") - volumesCmd.Flags().BoolVarP(&mal.SearchNSFW, "search-nsfw", "", false, "Include NSFW-rated items in search results") volumesCmd.Flags().BoolVarP(&queryOnlyMode, "query", "q", false, "Query only (don't update data)") volumesCmd.Flags().IntVarP(&entryId, "id", "i", -1, "Manually specify the ID of manga (overrides search)") volumesCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") + + volumesCmd.Flags().IntP("prompt-length", "l", 5, "Length of select prompt") + volumesCmd.Flags().IntP("search-length", "n", 10, "Amount of search results to load") + volumesCmd.Flags().IntP("search-offset", "o", 0, "Offset for the search results") + volumesCmd.Flags().BoolP("search-nsfw", "", false, "Include NSFW-rated items in search results") } |