From 355794f0b55ac7e6ea81efbefa438fd176ea0de6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 3 Nov 2024 11:51:50 +0200 Subject: move platform parsing to args --- internal/config/args.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/config/args.go b/internal/config/args.go index b06d2e2..b22ff95 100644 --- a/internal/config/args.go +++ b/internal/config/args.go @@ -2,7 +2,9 @@ package config import ( "fmt" + "log" "slices" + "strconv" "strings" "time" ) @@ -22,7 +24,26 @@ type Args struct { OAuth2Browser string } -func (a Args) Validate() error { +func (a *Args) ParsePlatforms(platforms string) error { + for _, platform := range strings.Split(platforms, ",") { + // E.g. Mastodon:500 + parts := strings.Split(platform, ":") + var err error + // E.g. args.Platform["mastodon"] = 500 + if len(parts) > 1 { + a.Platforms[parts[0]], err = strconv.Atoi(parts[1]) + if err != nil { + return err + } + } else { + log.Println("No message length specified for", platform, "so assuming 500") + a.Platforms[parts[0]] = 500 + } + } + return nil +} + +func (a *Args) Validate() error { for platform := range a.Platforms { if !slices.Contains(validPlatforms, strings.ToLower(platform)) { return fmt.Errorf("Platform %s not supported", platform) -- cgit v1.2.3