diff --git a/comitium.go b/comitium.go index 8228510..69df77a 100644 --- a/comitium.go +++ b/comitium.go @@ -14,6 +14,7 @@ import ( "net/url" "os" "path/filepath" + "strconv" "github.com/mitchellh/go-homedir" "golang.nytpu.com/comitium/localizations" @@ -68,7 +69,13 @@ func main() { // make sure it exists so we can start working with files in it os.MkdirAll(dataPath, os.ModePerm) - err := core.Init(dataPath, localizer, 0) + days, err := getHist() + if err != nil { + fmt.Fprint(os.Stderr, err) + os.Exit(1) + } + + err = core.Init(dataPath, localizer, days) if err != nil { fmt.Fprintf(os.Stderr, core.TranslateStringLocalizer( localizer, "%s\n", @@ -203,6 +210,13 @@ func getLang() *localizations.Localizer { return localizations.New(lang.String(), supportedLangs[0].String()) } +func getHist() (days int, err error) { + if env := os.Getenv("COMITIUM_HISTORY"); env != "" && *histFlag != 31 { + return strconv.Atoi(env) + } + return *histFlag, nil +} + func usage() { fmt.Fprintf(os.Stderr, "Usage:\n") fmt.Fprintf(os.Stderr, " %v [FLAGS] [ARGUMENTS]\n\n", os.Args[0]) diff --git a/flags.go b/flags.go index b634a41..11f3051 100644 --- a/flags.go +++ b/flags.go @@ -12,6 +12,7 @@ var ( dataFlag = globalFs.StringP("data", "d", "", "The data directory where comitium will store its files") langFlag = globalFs.StringP("lang", "l", "en-US", "The language that comitium will use when outputting its files") + histFlag = globalFs.IntP("history", "h", 31, "The number of days of article history to display on feed.gmi") ) // command holds fields used for printing information about a command.