aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 15:28:27 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 15:28:27 +0530
commite1bd26b9ad73cd0758ba77373c1cd07f72f47a65 (patch)
treebfcba01cdf2b5e0d3f659b097d3683eb83fb89d0 /util
parentd67758bdbeb162adadb6b19954e8e22cf04ed388 (diff)
reading both flags and config for list commands
Diffstat (limited to 'util')
-rw-r--r--util/bind_config.go43
1 files changed, 41 insertions, 2 deletions
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
+}