feat(comments): accept -d/--description for comment body (#1043)

Closes #1042.

### What

`tea issue create`, `tea issue edit` and `tea pr create` all take the body via
`-d` / `--description`, but `tea comments add` and `tea comments edit` only
accepted it positionally — passing `-d` errored with
`flag provided but not defined: -d`.

This adds `-d` / `--description` to both `comments` subcommands so every
body-bearing command shares one flag.

### Behaviour / precedence

Unchanged for existing usage. Body resolution is now:

1. positional argument (kept first for back-compat),
2. `-d` / `--description`,
3. piped stdin,
4. `$EDITOR` (interactive only).

### Testing

- `go build`, `go vet ./...`, `go test -short ./cmd/... ./modules/...` all pass.
- Manually verified `tea comments add --help` / `edit --help` list the flag,
  and that `-d` resolves the body (reaches the API, no parse error, no editor
  prompt, no stdin block).

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/1043
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Brien Coffield <coffbr01@gmail.com>
Co-committed-by: Brien Coffield <coffbr01@gmail.com>
This commit is contained in:
Brien Coffield
2026-06-29 00:52:24 +00:00
committed by Lunny Xiao
parent d4545d8ed7
commit 12947f068a
5 changed files with 171 additions and 25 deletions
+13 -14
View File
@@ -7,7 +7,6 @@ import (
stdctx "context"
"errors"
"fmt"
"io"
"strings"
gitea "gitea.dev/sdk"
@@ -32,7 +31,13 @@ var CmdCommentsAdd = cli.Command{
Description: "Add a comment to an issue or pull request.",
ArgsUsage: "<issue / pr index> [<comment body>]",
Action: RunCommentsAdd,
Flags: flags.AllDefaultFlags,
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "description",
Aliases: []string{"d"},
Usage: "comment body (alternative to the positional argument)",
},
}, flags.AllDefaultFlags...),
}
// RunCommentsAdd creates a new comment.
@@ -54,18 +59,12 @@ func RunCommentsAdd(requestCtx stdctx.Context, cmd *cli.Command) error {
return err
}
body := strings.Join(ctx.Args().Tail(), " ")
// Only consume stdin if no positional body was given. interact.IsStdinPiped()
// is true for any non-TTY stdin (CI, subshells, agent harnesses) — not just
// piped data — so reading unconditionally would block forever in those
// contexts when the body is supplied via args.
if len(body) == 0 && interact.IsStdinPiped() {
if bodyStdin, err := io.ReadAll(ctx.Reader); err != nil {
return err
} else if len(bodyStdin) != 0 {
body = string(bodyStdin)
}
} else if len(body) == 0 {
stdinPiped := interact.IsStdinPiped()
body, err := resolveBody(strings.Join(ctx.Args().Tail(), " "), ctx.String("description"), stdinPiped, ctx.Reader)
if err != nil {
return err
}
if len(body) == 0 && !stdinPiped {
if err := huh.NewForm(
huh.NewGroup(
huh.NewText().