add history flag

This commit is contained in:
nytpu
2021-05-19 08:07:36 -06:00
parent f9d8872260
commit c5b47f1546
2 changed files with 16 additions and 1 deletions
+15 -1
View File
@@ -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])