You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vibed/nbd/.beans/nbd-fgwx--nbd-update-diff-o...

57 lines
1.8 KiB
Markdown

---
# nbd-fgwx
title: nbd update diff output
status: completed
type: feature
priority: normal
created_at: 2026-03-10T23:30:30Z
updated_at: 2026-03-10T23:30:30Z
---
Show a git-diff-style +/- summary of what changed when `nbd update` is run without `--json`.
## Motivation
Currently `nbd update` prints the full ticket after the change, making it hard to see at a glance what actually changed. A diff view — showing only changed fields — is more informative.
## Approach
### display.rs
Add `format_diff(old: &Ticket, new: &Ticket) -> String`:
- Compare each field between `old` and `new`.
- For each field that changed, emit two lines:
```
- status: todo
+ status: in_progress
```
- If no fields changed, emit `(no changes)`.
- Fields compared: `title`, `body`, `priority`, `status`, `ticket_type`, `dependencies`.
- `id` is never shown (it cannot change).
- Label width matches `format_ticket` (LABEL_WIDTH).
Add `print_diff(old: &Ticket, new: &Ticket)` that calls `println!("{}" format_diff(...))`.
### main.rs
In `cmd_update`:
- Before applying changes: `let old = ticket.clone();`
- After `write_ticket`:
- If `json`: current behaviour (print new ticket as JSON).
- Else: `display::print_diff(&old, &ticket)`.
## Tests
Unit tests in `src/tests.rs`:
- `format_diff` shows changed fields only.
- `format_diff` with identical tickets outputs `(no changes)`.
- Changed dependencies are shown as comma-separated lists on each line.
Integration test:
- `nbd update <id> --status in_progress` (no `--json`) prints `- status:` and `+ status:` lines.
- `nbd update <id> --json` still prints full JSON (no diff).
## Files touched
- `src/display.rs``format_diff`, `print_diff`
- `src/main.rs``cmd_update` uses `print_diff`
- `src/tests.rs` — unit tests for `format_diff`
- `tests/integration.rs` — integration tests