From faf7569ab307eff706e4ccf2ed92eec5c93f67eb Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 22 Nov 2024 23:25:46 +0200 Subject: implement random other --- internal/run.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'internal/run.go') diff --git a/internal/run.go b/internal/run.go index b143cca..aeb2fc2 100644 --- a/internal/run.go +++ b/internal/run.go @@ -3,7 +3,7 @@ package internal import ( "context" "errors" - "log" + "fmt" "codeberg.org/snonux/gos/internal/colour" "codeberg.org/snonux/gos/internal/config" @@ -49,19 +49,27 @@ func runPlatform(ctx context.Context, args config.Args, platform platforms.Platf case err != nil: return err } + err = postPlatform(ctx, args, platform, 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) - var postCB func(context.Context, config.Args, int, entry.Entry) error switch platform.String() { case "mastodon": - postCB = mastodon.Post + err = mastodon.Post(ctx, args, sizeLimit, en) case "linkedin": - postCB = linkedin.Post + err = linkedin.Post(ctx, args, sizeLimit, en) default: - log.Fatal("Platform", platform, "(not yet) implemented") + err = fmt.Errorf("Platform '%s' (not yet) implemented", platform) } - if err := postCB(ctx, args, sizeLimit, en); err != nil { + if err != nil { return err } if err := en.MarkPosted(); err != nil { -- cgit v1.2.3