summaryrefslogtreecommitdiff
path: root/internal/run.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/run.go')
-rw-r--r--internal/run.go36
1 files changed, 6 insertions, 30 deletions
diff --git a/internal/run.go b/internal/run.go
index aeb2fc2..c0d8234 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -3,14 +3,10 @@ package internal
import (
"context"
"errors"
- "fmt"
"codeberg.org/snonux/gos/internal/colour"
"codeberg.org/snonux/gos/internal/config"
- "codeberg.org/snonux/gos/internal/entry"
"codeberg.org/snonux/gos/internal/platforms"
- "codeberg.org/snonux/gos/internal/platforms/linkedin"
- "codeberg.org/snonux/gos/internal/platforms/mastodon"
"codeberg.org/snonux/gos/internal/prompt"
"codeberg.org/snonux/gos/internal/queue"
"codeberg.org/snonux/gos/internal/schedule"
@@ -24,7 +20,11 @@ func Run(ctx context.Context, args config.Args) error {
colour.Infoln(err)
}
- for platform, sizeLimit := range args.Platforms {
+ for platformStr, sizeLimit := range args.Platforms {
+ platform, err := platforms.New(platformStr)
+ if err != nil {
+ return err
+ }
if err := runPlatform(ctx, args, platform, sizeLimit); err != nil {
if softError(err) {
colour.Infoln(err)
@@ -49,37 +49,13 @@ func runPlatform(ctx context.Context, args config.Args, platform platforms.Platf
case err != nil:
return err
}
- err = postPlatform(ctx, args, platform, sizeLimit, en)
+ err = platform.Post(ctx, args, sizeLimit, en)
if errors.Is(err, prompt.ErrRamdomOther) {
return runPlatform(ctx, args, platform, sizeLimit)
}
return err
}
-func postPlatform(ctx context.Context, args config.Args, platform platforms.Platform,
- sizeLimit int, en entry.Entry) (err error) {
-
- colour.Infoln("Posting", en)
- switch platform.String() {
- case "mastodon":
- err = mastodon.Post(ctx, args, sizeLimit, en)
- case "linkedin":
- err = linkedin.Post(ctx, args, sizeLimit, en)
- default:
- err = fmt.Errorf("Platform '%s' (not yet) implemented", platform)
- }
-
- if err != nil {
- return err
- }
- if err := en.MarkPosted(); err != nil {
- return err
- }
-
- colour.Successf("Successfully posted message to %s", platform)
- return nil
-}
-
func softError(err error) bool {
return errors.Is(err, prompt.ErrAborted) || errors.Is(err, prompt.ErrDeleted)
}