diff options
| author | Paul Buetow <paul@buetow.org> | 2025-01-04 22:34:30 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-01-04 22:34:30 +0200 |
| commit | 2f337e4924fd0e761b467dd2f81b8253022222c6 (patch) | |
| tree | f73cda1e8e056d7f4d4c8fc6001aee2b4dbc6426 /internal | |
| parent | a35f0ed04c28d80b902a00c3aec84dd86db34e85 (diff) | |
add --compose flag
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/args.go | 1 | ||||
| -rw-r--r-- | internal/platforms/linkedin/linkedin.go | 2 | ||||
| -rw-r--r-- | internal/platforms/mastodon/mastodon.go | 3 | ||||
| -rw-r--r-- | internal/prompt/file.go | 24 | ||||
| -rw-r--r-- | internal/run.go | 9 |
5 files changed, 32 insertions, 7 deletions
diff --git a/internal/config/args.go b/internal/config/args.go index 43687ac..2fbdf86 100644 --- a/internal/config/args.go +++ b/internal/config/args.go @@ -24,6 +24,7 @@ type Args struct { OAuth2Browser string SummaryFor []string GemtexterEnable bool + ComposeEntry bool } func (a *Args) ParsePlatforms(platformStrs string) error { diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go index 85b95af..ebbf5dd 100644 --- a/internal/platforms/linkedin/linkedin.go +++ b/internal/platforms/linkedin/linkedin.go @@ -62,7 +62,7 @@ func post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) } 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 { + if content, err = prompt.FileAction(question, content, en.Path, prompt.RandomOption); err != nil { return err } diff --git a/internal/platforms/mastodon/mastodon.go b/internal/platforms/mastodon/mastodon.go index 938cf6f..f52f905 100644 --- a/internal/platforms/mastodon/mastodon.go +++ b/internal/platforms/mastodon/mastodon.go @@ -26,7 +26,8 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) colour.Infoln("Not posting", en, "to Mastodon as dry-run enabled") return nil } - if content, err = prompt.FileAction("Do you want to post this message to Mastodon?", content, en.Path); err != nil { + if content, err = prompt.FileAction("Do you want to post this message to Mastodon?", + content, en.Path, prompt.RandomOption); err != nil { return err } diff --git a/internal/prompt/file.go b/internal/prompt/file.go index 804d26f..ea1ab00 100644 --- a/internal/prompt/file.go +++ b/internal/prompt/file.go @@ -16,17 +16,24 @@ var ( ErrAborted = errors.New("aborted") ErrDeleted = errors.New("deleted") ErrRamdomOther = errors.New("randomOther") + RandomOption = true ) -func FileAction(question, content, filePath string) (string, error) { +func FileAction(question, content, filePath string, includeRandomOption ...bool) (string, error) { colour.Info2f(filePath + ":") fmt.Print("\n") colour.Info2f(content) fmt.Print("\n") reader := bufio.NewReader(os.Stdin) + includeRandom := len(includeRandomOption) > 0 && includeRandomOption[0] == RandomOption + var randomOption string + if includeRandom { + randomOption = "/r=random other" + } + for { - colour.Ackf("%s (y=yes/n=no/e=edit/d=delete/r=random other):", question) + colour.Ackf("%s (y=yes/n=no/e=edit/d=delete%s):", question, randomOption) input, err := reader.ReadString('\n') if err != nil { return "", fmt.Errorf("error reading input: %w", err) @@ -44,16 +51,23 @@ func FileAction(question, content, filePath string) (string, error) { if content, err = oi.SlurpAndTrim(filePath); err != nil { return content, err } - return FileAction(question, content, filePath) + return FileAction(question, content, filePath, includeRandomOption...) case "d", "delete": if err := os.Remove(filePath); err != nil { return content, err } return content, fmt.Errorf("%w %s", ErrDeleted, filePath) case "r", "random", "random other": - return content, fmt.Errorf("%w %s", ErrRamdomOther, filePath) + if includeRandom { + return content, fmt.Errorf("%w %s", ErrRamdomOther, filePath) + } + fallthrough default: - fmt.Println("Please respond with one of [ynedr].") + var r string + if includeRandom { + r = "r" + } + fmt.Printf("Please respond with one of [yned%s].\n", r) } } } diff --git a/internal/run.go b/internal/run.go index 813bdf6..904477b 100644 --- a/internal/run.go +++ b/internal/run.go @@ -3,6 +3,8 @@ package internal import ( "context" "errors" + "fmt" + "time" "codeberg.org/snonux/gos/internal/colour" "codeberg.org/snonux/gos/internal/config" @@ -18,6 +20,13 @@ func Run(ctx context.Context, args config.Args) error { return summary.Run(ctx, args) } + if args.ComposeEntry { + entryPath := fmt.Sprintf("%s/%d.ask.txt", args.GosDir, time.Now().Unix()) + if err := prompt.EditFile(entryPath); err != nil { + return err + } + } + if err := queue.Run(args); err != nil { if !softError(err) { return err |
