/
purge.go
35 lines (31 loc) · 921 Bytes
/
purge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cmd
import (
"github.com/slurdge/goeland/internal/goeland/filters"
"github.com/slurdge/goeland/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func purge(cmd *cobra.Command, args []string) {
log.Debugln("Purging...")
config := viper.GetViper()
sources := config.GetStringMapString("sources")
numOfDays := config.GetInt("purge-days")
if numOfDays < 0 {
numOfDays = 0
}
for source := range sources {
filters.PurgeUnseen(config, source, numOfDays)
}
}
// versionCmd represents the version command
var purgeCmd = &cobra.Command{
Use: "purge",
Short: "Purge the database from old entries",
Run: purge,
}
func init() {
purgeCmd.Flags().Int("purge-days", 15, "Number of days to keep for the purge command")
viper.BindPFlag("purge-days", purgeCmd.Flags().Lookup("purge-days"))
bindFlags(purgeCmd, viper.GetViper())
rootCmd.AddCommand(purgeCmd)
}