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
@@ -0,0 +1,37 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package comments
|
||||
|
||||
import "io"
|
||||
|
||||
// resolveBody picks the comment body from the non-interactive sources, in
|
||||
// precedence order:
|
||||
//
|
||||
// 1. the positional argument (kept first for back-compat with the historical
|
||||
// 'tea comment <idx> "<body>"' shorthand),
|
||||
// 2. the -d/--description flag (mirrors the body flag on 'issue create',
|
||||
// 'issue edit' and 'pr create'),
|
||||
// 3. piped stdin.
|
||||
//
|
||||
// stdin is only read when stdinPiped is true (a non-TTY stdin, e.g. CI,
|
||||
// subshells or agent harnesses) and no body was supplied otherwise, so the
|
||||
// command never blocks reading an interactive terminal when a body is already
|
||||
// given. An empty result means the caller should fall back to the editor (when
|
||||
// interactive) or error out.
|
||||
func resolveBody(positional, description string, stdinPiped bool, stdin io.Reader) (string, error) {
|
||||
if len(positional) != 0 {
|
||||
return positional, nil
|
||||
}
|
||||
if len(description) != 0 {
|
||||
return description, nil
|
||||
}
|
||||
if stdinPiped {
|
||||
stdinBytes, err := io.ReadAll(stdin)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(stdinBytes), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
Reference in New Issue
Block a user