From e1bd26b9ad73cd0758ba77373c1cd07f72f47a65 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 30 Sep 2022 15:28:27 +0530 Subject: reading both flags and config for list commands --- util/bind_config.go | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/bind_config.go b/util/bind_config.go index f849398..2ab6cc9 100644 --- a/util/bind_config.go +++ b/util/bind_config.go @@ -36,10 +36,18 @@ type SearchConfig struct { SearchNSFW bool } +type ListConfig struct { + ResultsLength int + ResultsOffset int + IncludeNSFW bool +} + // handles prompt-length, search-length, search-offset and search-nsfw func BindSearchConfig(flags *pflag.FlagSet) (SearchConfig, error) { - var conf SearchConfig - var err error + var ( + conf SearchConfig + err error + ) if flags.Lookup("prompt-length").Changed { conf.PromptLength, err = flags.GetInt("prompt-length") @@ -71,3 +79,34 @@ func BindSearchConfig(flags *pflag.FlagSet) (SearchConfig, error) { return conf, nil } + +// handles results-length, results-offset, include-nsfw +func BindListConfig(flags *pflag.FlagSet) (ListConfig, error) { + var ( + conf ListConfig + err error + ) + + if flags.Lookup("results-length").Changed { + conf.ResultsLength, err = flags.GetInt("results-length") + if err != nil {return conf, err} + } else { + conf.ResultsLength = viper.GetInt("lists.list_length") + } + + if flags.Lookup("results-offset").Changed { + conf.ResultsOffset, err = flags.GetInt("results-offset") + if err != nil {return conf, err} + } else { + conf.ResultsOffset = viper.GetInt("lists.list_offset") + } + + if flags.Lookup("include-nsfw").Changed { + conf.IncludeNSFW, err = flags.GetBool("include-nsfw") + if err != nil {return conf, err} + } else { + conf.IncludeNSFW = viper.GetBool("lists.include_nsfw_results") + } + + return conf, nil +} -- cgit v1.2.3