summaryrefslogtreecommitdiff
path: root/internal/run.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-09 23:44:09 +0300
committerPaul Buetow <paul@buetow.org>2024-10-09 23:44:09 +0300
commitaf7c12e5d42b6a19fd657138862ca6db6942d402 (patch)
tree7a7914fa145e7affafc1bb8e4abadcebef12dacb /internal/run.go
parent8e23c12025fac69c6c08aa37e690ee24978c6eed (diff)
refactor
Diffstat (limited to 'internal/run.go')
-rw-r--r--internal/run.go53
1 files changed, 21 insertions, 32 deletions
diff --git a/internal/run.go b/internal/run.go
index 0457f36..b79c4ea 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -7,6 +7,7 @@ import (
"strings"
"codeberg.org/snonux/gos/internal/config"
+ "codeberg.org/snonux/gos/internal/entry"
"codeberg.org/snonux/gos/internal/platforms/linkedin"
"codeberg.org/snonux/gos/internal/platforms/mastodon"
"codeberg.org/snonux/gos/internal/prompt"
@@ -31,46 +32,34 @@ func Run(ctx context.Context, args config.Args) error {
case err != nil:
return err
}
+ if args.DryRun {
+ log.Println("Not posting", ent, "to", platform, "as dry-run enabled")
+ return nil
+ }
log.Println("Scheduling", ent)
+ var postCB func(context.Context, config.Args, entry.Entry) error
switch strings.ToLower(platform) {
case "mastodon":
- if args.DryRun {
- log.Println("Not posting", ent, "to", platform, "as dry-run enabled")
- continue
- }
- if err := mastodon.Post(ctx, args, ent); err != nil {
- if errors.Is(err, prompt.ErrAborted) {
- log.Println("Aborted posting to", platform)
- continue
- }
- return err
- }
- if err := ent.MarkPosted(); err != nil {
- return err
- }
- log.Println("Posted", ent, "to", platform)
+ postCB = mastodon.Post
case "linkedin":
- if args.DryRun {
- log.Println("Not posting", ent, "to", platform, "as dry-run enabled")
- continue
- }
- if err := linkedin.Post(ctx, args, ent); err != nil {
- if errors.Is(err, prompt.ErrAborted) {
- log.Println("Aborted posting to", platform)
- continue
- }
- return err
- }
- if err := ent.MarkPosted(); err != nil {
- return err
- }
- log.Println("Posted", ent, "to", platform)
+ postCB = linkedin.Post
default:
- // TODO: Once we have LinkedIn implemented, make the above code
- // more generic so that it can be used with LinkedIn as well.
log.Fatal("Platform", platform, "(not yet) implemented")
}
+
+ if err := postCB(ctx, args, ent); err != nil {
+ if errors.Is(err, prompt.ErrAborted) {
+ log.Println("Aborted posting to", platform)
+ continue
+ }
+ return err
+ }
+
+ log.Println("Posted", ent, "to", platform)
+ if err := ent.MarkPosted(); err != nil {
+ return err
+ }
}
return nil