summaryrefslogtreecommitdiff
path: root/internal/config/args.go
blob: be7353bf589293b3ae348c6ba9262c7f9766cba1 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package config

import (
	"strconv"
	"strings"
	"time"

	"codeberg.org/snonux/gos/internal/colour"
)

type Args struct {
	GosDir           string
	CacheDir         string
	DryRun           bool
	Platforms        map[string]int // Platform and post size limits
	Target           int
	MinQueued        int
	MaxDaysQueued    int
	PauseDays        int
	RunInterval      time.Duration
	Lookback         time.Duration
	ConfigPath       string
	Config           Config
	OAuth2Browser    string
	GeminiSummaryFor []string
	GemtexterEnable  bool
	GeminiCapsules   []string
	ComposeMode      bool
	StatsOnly        bool
}

func (a *Args) ParsePlatforms(platformStrs string) error {
	a.Platforms = make(map[string]int)

	for _, platformInfo := range strings.Split(platformStrs, ",") {
		// E.g. Mastodon:500
		parts := strings.Split(platformInfo, ":")
		platformStr := parts[0]

		// E.g. args.Platform["mastodon"] = 500
		if len(parts) > 1 {
			var err error
			a.Platforms[platformStr], err = strconv.Atoi(parts[1])
			if err != nil {
				return err
			}
		} else {
			colour.Infoln("No message length specified for", platformStr, "so assuming 500")
			a.Platforms[platformStr] = 500
		}
	}
	return nil
}