mirror of
https://gitea.com/gitea/tea.git
synced 2026-07-16 02:57:40 +02:00
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:
committed by
Lunny Xiao
parent
d4545d8ed7
commit
12947f068a
+14
-11
@@ -7,7 +7,6 @@ import (
|
||||
stdctx "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
@@ -31,10 +30,16 @@ var CmdCommentsEdit = cli.Command{
|
||||
Usage: "Edit the body of an existing comment",
|
||||
Description: `Edit the body of an existing comment by its comment ID. Use 'tea comments list <issue>' to find IDs.
|
||||
|
||||
The new body can be supplied as a positional argument, piped on stdin, or (if neither is given and stdin is a terminal) entered in your $EDITOR.`,
|
||||
The new body can be supplied as a positional argument, via -d/--description, piped on stdin, or (if none is given and stdin is a terminal) entered in your $EDITOR.`,
|
||||
ArgsUsage: "<comment id> [<new body>]",
|
||||
Action: RunCommentsEdit,
|
||||
Flags: flags.AllDefaultFlags,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "description",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "new comment body (alternative to the positional argument)",
|
||||
},
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
// RunCommentsEdit updates the body of an existing comment.
|
||||
@@ -56,14 +61,12 @@ func RunCommentsEdit(requestCtx stdctx.Context, cmd *cli.Command) error {
|
||||
return fmt.Errorf("invalid comment id %q: %s", ctx.Args().First(), err)
|
||||
}
|
||||
|
||||
body := strings.Join(ctx.Args().Tail(), " ")
|
||||
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 {
|
||||
// Fetch current body to pre-populate the editor.
|
||||
client := ctx.Login.Client()
|
||||
current, _, fetchErr := client.Issues.GetIssueComment(requestCtx, ctx.Owner, ctx.Repo, id)
|
||||
|
||||
Reference in New Issue
Block a user