From be3abe2462bca511ede21cacd1e5a3690b5aa745 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 9 Oct 2024 23:52:54 +0300 Subject: refator --- internal/run.go | 66 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'internal/run.go') 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() +} -- cgit v1.2.3