Two duration parsers, and the documented --older-than example deletes almost every snapshot #123

Open
opened 2026-09-21 09:19:44 +02:00 by clawbot · 0 comments
Collaborator

Two functions named parseDuration exist with different grammars: internal/cli/duration.go (decimal values, all Go units, plus d/w/mo/y) and internal/vaultik/helpers.go (integer values, Go units via time.ParseDuration first, plus d/w/mo/y). snapshot purge --older-than goes through the second one (internal/vaultik/snapshot.go:554).

The user-facing trap: README.md:254 gives 6m as the months example for --older-than. Both parsers read m as minutes, so vaultik snapshot purge --older-than 6m removes every snapshot older than six minutes. That is a retention flag on a destructive command whose documented example deletes almost everything. --keep-newer-than documents 6mo for the same meaning (README.md:205-207), so the two flags on the same tool disagree in their docs about the same unit.

Definition of done

  1. One duration parser, in one package, used by every flag and config value that takes a duration. The other is deleted. Which one survives is the implementer's call; state it in the PR.
  2. m means minutes everywhere (Go convention) and mo means months everywhere, and the help text of --older-than and --keep-newer-than both say so with the same example list.
  3. README.md:254 and any other doc example that uses m for months is corrected to mo.
  4. Table-driven tests for the surviving parser cover: every unit; 6m is six minutes; 6mo is 180 days; a bare number, an unknown unit, and a negative value are rejected.
  5. No other behavior change. make check green.

Model: fable-5-1

Two functions named `parseDuration` exist with different grammars: `internal/cli/duration.go` (decimal values, all Go units, plus `d`/`w`/`mo`/`y`) and `internal/vaultik/helpers.go` (integer values, Go units via `time.ParseDuration` first, plus `d`/`w`/`mo`/`y`). `snapshot purge --older-than` goes through the second one (`internal/vaultik/snapshot.go:554`). The user-facing trap: `README.md:254` gives `6m` as the months example for `--older-than`. Both parsers read `m` as minutes, so `vaultik snapshot purge --older-than 6m` removes every snapshot older than six minutes. That is a retention flag on a destructive command whose documented example deletes almost everything. `--keep-newer-than` documents `6mo` for the same meaning (`README.md:205-207`), so the two flags on the same tool disagree in their docs about the same unit. ## Definition of done 1. One duration parser, in one package, used by every flag and config value that takes a duration. The other is deleted. Which one survives is the implementer's call; state it in the PR. 2. `m` means minutes everywhere (Go convention) and `mo` means months everywhere, and the help text of `--older-than` and `--keep-newer-than` both say so with the same example list. 3. `README.md:254` and any other doc example that uses `m` for months is corrected to `mo`. 4. Table-driven tests for the surviving parser cover: every unit; `6m` is six minutes; `6mo` is 180 days; a bare number, an unknown unit, and a negative value are rejected. 5. No other behavior change. `make check` green. Model: fable-5-1
clawbot added this to the 1.0.0 milestone 2026-09-21 09:19:44 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/vaultik#123