gitea.tea/modules/print
dinsmoor 09fc09c2f7 feat(comments): add list/edit/delete subcommands to tea comment (#1015)
## Why

Today `tea comment` can only *add* a comment. Editing or deleting requires falling back to `tea api`. This came up while I was iterating on PRs in this same repo earlier today and had to correct a couple of comments by hand. Every comparable forge CLI (gh, glab, etc.) exposes these operations as first-class commands.

## What

Restructures `tea comment` from a single-action command into a parent with four subcommands. The parent's default action remains the existing "add" behavior, so the historical shorthand keeps working.

| Command | Purpose |
|---|---|
| `tea comment add <idx> [<body>]` | Add a comment (explicit subcommand) |
| `tea comment list <idx>` | Tabular listing including comment IDs |
| `tea comment edit <id> [<body>]` | Replace the body of one comment |
| `tea comment delete <id> [<id>...]` | Delete one or more comments |
| `tea comment <idx> [<body>]` | Unchanged — still routes to `add` |

The `list` command exists specifically so users can discover the IDs that `edit` and `delete` accept.

## Backward compatibility

The whole point of routing the parent's default `Action` through `add` is to preserve every existing invocation. `tea comment 1 "body"` still does what it did before. No flag or arg names change.

## Input forms (for add and edit)

Same pattern as the original `tea comment`:

1. Positional body (`tea comment edit <id> "new body"`) — wins if present.
2. Piped stdin if no positional body is given.
3. External `$EDITOR` (pre-populated with the current body, on `edit`) if neither.

This matches the stdin-handling fix in #1011 — positional body wins over a non-TTY stdin so the command doesn't hang in CI/subshells.

## Verification

All four subcommands were exercised live against `https://gitea.com/dinsmoor/tea-testing` issue #1. The test artifacts and a summary log are visible on that issue right now. Specifically:

- The annotated summary comment lists every operation tested and the comment IDs each one acted on.
- Comments 1197162 (legacy add), 1197163 (subcommand add, later edited), 1197164 (stdin add) are still there to be inspected.
- Comment 1197166 was created and then deleted; its absence from `tea comment list` output is evidence that delete works.

## New files

- `cmd/comments/add.go` — extracted from the old `cmd/comment.go`
- `cmd/comments/list.go`
- `cmd/comments/edit.go`
- `cmd/comments/delete.go`
- `modules/print/comment.go` — adds `CommentsList` helper for the tabular output

`cmd/comment.go` is rewritten as a thin parent that wires these together.

## Open questions for the reviewer

- **Naming**: should the top-level command be `comments` (plural) or stay `comment` (singular)? I kept it singular with `comments` as an alias to match the existing user-visible name.
- **Delete confirmation**: I did not add a confirmation prompt — `delete` just deletes. Some projects gate this behind `--yes` / interactive `[y/N]`. I'd rather follow whatever convention the maintainers prefer.
- **Output format on list**: currently uses the existing `print.tableWithHeader` helper, matching `tea organizations list` etc. Other tea listings support `--output json` / `--output csv` via the shared `--output` flag, which works here automatically through the same helper.

---

This patch was authored interactively with an AI assistant, driven and reviewed by a human (Tyler / @dinsmoor) every step.

*pull request created by Tyler's lovingly wrangled demon machine <3*

Reviewed-on: https://gitea.com/gitea/tea/pulls/1015
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: dinsmoor <204368+dinsmoor@noreply.gitea.com>
Co-committed-by: dinsmoor <204368+dinsmoor@noreply.gitea.com>
2026-05-31 22:20:48 +00:00
..
actions.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
actions_runs.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
actions_runs_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
actions_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
attachment.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
branch.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
branch_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
comment.go feat(comments): add list/edit/delete subcommands to tea comment (#1015) 2026-05-31 22:20:48 +00:00
formatters.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
issue.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
label.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login.go update import path to use gitea.dev (#1003) 2026-05-23 17:26:43 +00:00
markdown.go Update to charm libraries v2 (#923) 2026-03-09 16:36:00 +00:00
milestone.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
notification.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
organization.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull.go fix(print): distinguish draft PRs from conflicting PRs (#1012) 2026-05-28 17:29:00 +00:00
pull_review_comment.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
release.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
repo.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
repo_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
sshkey.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
table.go refactor: code cleanup across codebase (#947) 2026-04-08 03:38:49 +00:00
table_test.go replace log.Fatal/os.Exit with error returns (#941) 2026-03-27 03:36:44 +00:00
times.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
user.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
webhook.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
webhook_test.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
wiki.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00
wiki_test.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00