diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 22:46:05 +0200 |
| commit | 836d21a7c43f4ce84dfa1ada0552989be4a43ca9 (patch) | |
| tree | fe6dc637c2c916e10b1beff31d687edf0f994503 /internal/config | |
| parent | 1550fbf9c2b0602c4675f25cd92e389593894e58 (diff) | |
use of platform aliases
Diffstat (limited to 'internal/config')
| -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) } } |
