#!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.11" # dependencies = [] # /// import argparse import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from tasks_common import FILENAME_RE, TASKS, log def find_by_slug(done: Path, slug: str) -> list[Path]: return [f for f in done.glob("*.md") if (m := FILENAME_RE.match(f.name)) and m.group(2) == slug] def main() -> int: parser = argparse.ArgumentParser(description="Archive tasks from done/ to archive/") group = parser.add_mutually_exclusive_group(required=True) group.add_argument("--all", action="store_true", help="Archive all tasks in done/") group.add_argument("--slug", action="append", dest="slugs", metavar="SLUG", help="Archive a specific task by slug (repeatable)") args = parser.parse_args() archive = TASKS / "archive" archive.mkdir(exist_ok=True) done = TASKS / "done" if args.all: targets = list(done.glob("*.md")) else: targets = [] for slug in args.slugs: matches = find_by_slug(done, slug) if not matches: print(f"Not found in done/: {slug}", file=sys.stderr) return 1 targets.extend(matches) if not targets: print("Nothing to archive.") return 0 for f in targets: f.rename(archive / f.name) log(f"ARCHIVE {f.name}") print(f"Archived {len(targets)} task(s).") return 0 if __name__ == "__main__": sys.exit(main())