diff options
| author | nytpu <alex@nytpu.com> | 2021-05-19 08:07:36 -0600 |
|---|---|---|
| committer | nytpu <alex@nytpu.com> | 2021-05-19 08:07:36 -0600 |
| commit | c5b47f15465cfbd0d7e02008374a5e78a6c51d51 (patch) | |
| tree | 585a2740ade92a63f944990d079aa24d9d6aa96c | |
| parent | f9d88722606e5c2570fe4237a64b5a1b22bf1789 (diff) | |
add history flag
| -rw-r--r-- | comitium.go | 16 | ||||
| -rw-r--r-- | flags.go | 1 |
2 files changed, 16 insertions, 1 deletions
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 <command> [FLAGS] [ARGUMENTS]\n\n", os.Args[0]) @@ -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. |
