github.com/wtfutil/wtf@v0.43.0/modules/subreddit/settings.go (about) 1 package subreddit 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/wtfutil/wtf/cfg" 6 ) 7 8 const ( 9 defaultFocusable = true 10 ) 11 12 // Settings contains the settings for the subreddit view 13 type Settings struct { 14 *cfg.Common 15 16 subreddit string `help:"Subreddit to look at" optional:"false"` 17 numberOfPosts int `help:"Number of posts to show. Default is 10." optional:"true"` 18 sortOrder string `help:"Sort order for the posts (hot, new, rising, top), default hot" optional:"true"` 19 topTimePeriod string `help:"If top sort is selected, the time period to show posts from (hour, week, day, month, year, all, default all)"` 20 } 21 22 // NewSettingsFromYAML creates the settings for this module from a yaml file 23 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 24 subreddit := ymlConfig.UString("subreddit") 25 settings := Settings{ 26 Common: cfg.NewCommonSettingsFromModule(name, subreddit, defaultFocusable, ymlConfig, globalConfig), 27 28 numberOfPosts: ymlConfig.UInt("numberOfPosts", 10), 29 sortOrder: ymlConfig.UString("sortOrder", "hot"), 30 topTimePeriod: ymlConfig.UString("topTimePeriod", "all"), 31 subreddit: subreddit, 32 } 33 34 return &settings 35 }