diff options
Diffstat (limited to 'internal/config/args.go')
| -rw-r--r-- | internal/config/args.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/internal/config/args.go b/internal/config/args.go index a0fa0ea..d1d8fe8 100644 --- a/internal/config/args.go +++ b/internal/config/args.go @@ -8,6 +8,7 @@ import ( "time" "codeberg.org/snonux/gos/internal/colour" + "codeberg.org/snonux/gos/internal/platforms" ) var validPlatforms = []string{"mastodon", "linkedin"} @@ -16,7 +17,7 @@ type Args struct { GosDir string CacheDir string DryRun bool - Platforms map[string]int // Platform name and post size limits + Platforms map[platforms.Platform]int // Platform and post size limits Target int MinQueued int MaxDaysQueued int @@ -27,20 +28,26 @@ type Args struct { OAuth2Browser string } -func (a *Args) ParsePlatforms(platforms string) error { - for _, platform := range strings.Split(platforms, ",") { +func (a *Args) ParsePlatforms(platformStrs string) error { + a.Platforms = make(map[platforms.Platform]int) + + for _, platformStr := range strings.Split(platformStrs, ",") { // E.g. Mastodon:500 - parts := strings.Split(platform, ":") - var err error + parts := strings.Split(platformStr, ":") + platform, err := platforms.New(parts[0]) + if err != nil { + return err + } + // E.g. args.Platform["mastodon"] = 500 if len(parts) > 1 { - a.Platforms[parts[0]], err = strconv.Atoi(parts[1]) + a.Platforms[platform], err = strconv.Atoi(parts[1]) if err != nil { return err } } else { colour.Infoln("No message length specified for", platform, "so assuming 500") - a.Platforms[parts[0]] = 500 + a.Platforms[platform] = 500 } } return nil @@ -48,7 +55,7 @@ func (a *Args) ParsePlatforms(platforms string) error { func (a *Args) Validate() error { for platform := range a.Platforms { - if !slices.Contains(validPlatforms, strings.ToLower(platform)) { + if !slices.Contains(validPlatforms, platform.String()) { return fmt.Errorf("Platform %s not supported", platform) } } |
