diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-22 23:25:46 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-22 23:25:46 +0200 |
| commit | faf7569ab307eff706e4ccf2ed92eec5c93f67eb (patch) | |
| tree | fa81064795ec6f742c5fc3eab314c83abdd2e5de /internal | |
| parent | b6f1f3f602df0368ac7ecec211e6c95b93a1c53c (diff) | |
implement random other
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/platforms/linkedin/linkedin.go | 2 | ||||
| -rw-r--r-- | internal/prompt/file.go | 10 | ||||
| -rw-r--r-- | internal/run.go | 20 |
3 files changed, 20 insertions, 12 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go index 9ca929b..7db0e0d 100644 --- a/internal/platforms/linkedin/linkedin.go +++ b/internal/platforms/linkedin/linkedin.go @@ -57,8 +57,6 @@ func post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) return err } - // TODO: Refactor this. Make it so that in a loop we can also check for the content with limit. - // Maybe pass an interface en.ContentWithLimit and en.Path() to prompt.FileAction question := fmt.Sprintf("Do you want to post this message to Linkedin (%v)?", prev) if content, err = prompt.FileAction(question, content, en.Path); err != nil { return err diff --git a/internal/prompt/file.go b/internal/prompt/file.go index 9668aed..2a23591 100644 --- a/internal/prompt/file.go +++ b/internal/prompt/file.go @@ -13,11 +13,11 @@ import ( ) var ( - ErrAborted = errors.New("aborted") - ErrDeleted = errors.New("deleted") + ErrAborted = errors.New("aborted") + ErrDeleted = errors.New("deleted") + ErrRamdomOther = errors.New("randomOther") ) -// TODO: Add option to randomly select another entry when no selected? func FileAction(question, content, filePath string) (string, error) { colour.Info2f(filePath + ":") fmt.Print("\n") @@ -26,7 +26,7 @@ func FileAction(question, content, filePath string) (string, error) { reader := bufio.NewReader(os.Stdin) for { - colour.Ackf("%s (y=yes/n=no/e=edit/d=delete):", question) + colour.Ackf("%s (y=yes/n=no/e=edit/d=delete/r=random other):", question) input, err := reader.ReadString('\n') if err != nil { fmt.Println("Error reading input:", err) @@ -51,6 +51,8 @@ func FileAction(question, content, filePath string) (string, error) { return content, err } return content, fmt.Errorf("%w %s", ErrDeleted, filePath) + case "r", "random", "random other": + return content, fmt.Errorf("%w %s", ErrRamdomOther, filePath) default: fmt.Println("Please enter 'y' or 'n' or 'e' or 'd'.") } 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 { |
