diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-09 23:52:54 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-09 23:52:54 +0300 |
| commit | be3abe2462bca511ede21cacd1e5a3690b5aa745 (patch) | |
| tree | 7028dfbd0ffe9f386ff7605ef544470db09cd766 /internal/run.go | |
| parent | af7c12e5d42b6a19fd657138862ca6db6942d402 (diff) | |
refator
Diffstat (limited to 'internal/run.go')
| -rw-r--r-- | internal/run.go | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/internal/run.go b/internal/run.go index b79c4ea..acf0525 100644 --- a/internal/run.go +++ b/internal/run.go @@ -21,46 +21,46 @@ func Run(ctx context.Context, args config.Args) error { } for _, platform := range args.Platforms { - ent, err := schedule.Run(args, platform) - switch { - case errors.Is(err, schedule.ErrNothingToSchedule): - log.Println("Nothing to be scheduled for", platform) - return nil - case errors.Is(err, schedule.ErrNothingQueued): - log.Println("Nothing queued for", platform) - return nil - 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": - postCB = mastodon.Post - case "linkedin": - postCB = linkedin.Post - default: - log.Fatal("Platform", platform, "(not yet) implemented") - } - - if err := postCB(ctx, args, ent); err != nil { + if err := runPlatform(ctx, args, platform); 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 } + +func runPlatform(ctx context.Context, args config.Args, platform string) error { + ent, err := schedule.Run(args, platform) + switch { + case errors.Is(err, schedule.ErrNothingToSchedule): + log.Println("Nothing to be scheduled for", platform) + return nil + case errors.Is(err, schedule.ErrNothingQueued): + log.Println("Nothing queued for", platform) + return nil + case err != nil: + return err + } + + log.Println("Scheduling", ent) + var postCB func(context.Context, config.Args, entry.Entry) error + switch strings.ToLower(platform) { + case "mastodon": + postCB = mastodon.Post + case "linkedin": + postCB = linkedin.Post + default: + log.Fatal("Platform", platform, "(not yet) implemented") + } + + if err := postCB(ctx, args, ent); err != nil { + return err + } + + log.Println("Posted", ent, "to", platform) + return ent.MarkPosted() +} |
