diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-03 11:51:50 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-03 11:51:50 +0200 |
| commit | 355794f0b55ac7e6ea81efbefa438fd176ea0de6 (patch) | |
| tree | f4c8c04be14cc83477603901bbbc1bbcbf5cd605 /internal | |
| parent | acb0d5e00c0b19e149eef429881b998414555a5d (diff) | |
move platform parsing to args
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/args.go | 23 |
1 files changed, 22 insertions, 1 deletions
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) |
