feat: archive and purge commands#2
Merged
Merged
Conversation
Parses friendly forms (Nd, Nw, Nm, Ny) plus Go duration fallback for multi-unit strings. Used by the upcoming archive/purge --older-than flags.
Pure split (kept/removed) and an in-place slice swap that leaves Header alone. Both are stepping stones for archive/purge so they can compute the surviving slice externally without poking at internals.
Moves Done tasks to a sibling .tsk.archive.md. Default cutoff is 30 days completed; --all overrides, --dry-run previews. Archived tasks get fresh sequential IDs in the archive file (continuing from its max); active task IDs stay stable. Atomic writes for both files.
Hard-deletes tasks. Refuses to run without --done or --id so a typo can't nuke the file. --older-than restricts --done to old completed tasks, --dry-run previews, missing --id surfaces an error. Surviving task IDs are preserved.
Adds a usage subsection covering tsk archive and tsk purge, the .tsk.archive.md location, accepted --older-than syntax, dry-run behavior, and the purge refusal-without-selection guarantee.
Table-driven ParseDuration coverage including the Nm-means-months disambiguation. Partition + ReplaceTasks unit tests. End-to-end archive/purge tests exercising happy path, --dry-run, --all, --older-than, refusal without selection, --id, and ID continuation across two archive runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's new
Two new commands plus a shared duration helper.
tsk archiveMove Done tasks out of the active
.tsk.mdand into a sibling.tsk.archive.mdin the same directory. Defaults to a 30-day cutoff so freshly-completed tasks stay in your face.Archived tasks get fresh sequential IDs in the archive file (continuing from the archive's existing max). Active task IDs do not renumber.
tsk purgeHard-deletes tasks. Refuses to run without an explicit selection.
Why both together
Both commands share
--older-thansemantics, so the duration helper lives ininternal/store/duration.goand is reused. Pairing them in one PR also avoids the awkward window where archive ships without a way to nuke truly stale stuff.--older-thanaccepts:Nddays,Nwweeks,Nmmonths (~30d),Nyyears (~365d), plus multi-unit Go durations like24hor1h30m.Safety story
archiveandpurgeboth support--dry-runand surface what they'd change before doing it.purgerefuses to run without--doneor--id(exit 2). No "oops, I forgot a flag" footgun.--id Nexits with an error so typos surface instead of silently no-op'ing.# tsk archiveheader on first creation so it's obvious what it is.Surface
internal/store/duration.goParseDurationinternal/store/markdown.goPartition,ReplaceTasksinternal/commands/archive.gotsk archiveinternal/commands/purge.gotsk purgeinternal/commands/root.goREADME.mdinternal/store/duration_test.gointernal/store/markdown_test.goPartition,ReplaceTasksinternal/commands/archive_test.goTests
go vet ./...,gofmt -w .,go test ./... -count=1all green. Coverage adds happy paths, dry-run,--all,--older-than,--id, refusal-without-selection, and ID continuation across two archive runs.No new external deps. No force-push. Existing tests untouched.