Metadata-Version: 2.4
Name: moyudeyumo-cli-todo
Version: 0.1.0
Summary: 一个用 Python 写的命令行待办事项工具
Author: moyudeyumo-gyy
License: MIT
Project-URL: Homepage, https://github.com/moyudeyumo-gyy/cli-todo
Project-URL: Repository, https://github.com/moyudeyumo-gyy/cli-todo
Keywords: todo,cli,task,productivity
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: rich>=13.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"

![Tests](https://github.com/moyudeyumo-gyy/cli-todo/actions/workflows/test.yml/badge.svg)

# CLI Todo 📝

一个用 Python 写的命令行待办事项工具，支持**优先级**、**截止日期**、**搜索**、**JSON 输出**和**彩色表格**。

## ✨ 功能

- ➕ 添加待办（可指定优先级和截止日期）
- 📋 查看待办列表（按优先级和日期智能排序）
- ✏️ 编辑待办（改内容 / 优先级 / 截止日期）
- ✅ 标记完成
- 🗑️ 删除待办
- 🔍 按关键词搜索
- 📊 统计信息（总数 / 已完成 / 待办）
- 🎨 彩色表格输出，过期任务高亮警告
- 🤖 JSON 输出格式，方便脚本调用

## 📦 环境要求

- Python 3.10+
- 依赖：[rich](https://github.com/Textualize/rich)

## 🚀 安装

```bash
# 克隆项目
git clone https://github.com/moyudeyumo-gyy/cli-todo.git
cd cli-todo

# 安装依赖
pip install -r requirements.txt
```

## 📖 使用方法

### 添加待办

```bash
# 基础用法（默认中等优先级）
python src/main.py add "买牛奶"

# 指定优先级（high / mid / low，也支持 h / m / l）
python src/main.py add "写周报" -p high

# 指定截止日期（YYYY-MM-DD）
python src/main.py add "交作业" -d 2026-09-20

# 两者都指定
python src/main.py add "准备面试" -p high -d 2026-10-01
```

### 查看列表

```bash
python src/main.py list
```

列表会按 **未完成 → 高优先级 → 截止日期近** 的顺序排列，过期任务显示**红色警告**。

### 编辑待办

```bash
# 只改内容
python src/main.py edit 2 "新的内容"

# 只改优先级
python src/main.py edit 2 -p high

# 只改截止日期
python src/main.py edit 2 -d 2026-12-31

# 清空截止日期
python src/main.py edit 2 -d none

# 一次改多个
python src/main.py edit 2 "新内容" -p low -d 2026-10-01
```

### 搜索

```bash
# 按关键词搜索（不区分大小写）
python src/main.py search 牛奶
python src/main.py search python
```

### 标记完成 / 删除

```bash
python src/main.py done 1      # 把 ID 为 1 的标记完成
python src/main.py delete 1    # 删除 ID 为 1 的
```

### 统计

```bash
python src/main.py stats
# 输出示例：📊 共 7 条：3 已完成 / 4 待办
```

### JSON 输出（方便脚本调用）

所有查询命令都支持 `--json` 参数：

```bash
python src/main.py list --json
python src/main.py stats --json
python src/main.py search 牛奶 --json
```

**示例**：用 `jq` 提取所有高优先级待办

```bash
python src/main.py list --json | jq '.[] | select(.priority=="high")'
```

**示例**：统计待办数量

```bash
python src/main.py stats --json | jq '.pending'
```

### 查看帮助

```bash
python src/main.py -h          # 总帮助
python src/main.py add -h      # add 命令的帮助
```

## 🧪 运行测试

本项目使用 [pytest](https://pytest.org/) 做单元测试，并用 [GitHub Actions](https://github.com/features/actions) 自动运行。

```bash
# 运行所有测试
pytest

# 查看详细输出
pytest -v

# 查看测试覆盖率
pytest --cov=src --cov-report=term-missing
```

当前测试覆盖：

- `src/db.py`：**94%**
- `src/main.py`（辅助函数）：**33%**

## 📁 项目结构

```
cli-todo/
├── .github/
│   └── workflows/
│       └── test.yml          # GitHub Actions 配置
├── src/
│   ├── db.py                 # 数据库层（SQLite）
│   └── main.py               # 主程序 + CLI 入口
├── tests/                    # 单元测试
│   ├── __init__.py
│   ├── test_db.py            # db.py 的测试
│   └── test_main.py          # main.py 辅助函数的测试
├── migrate.py                # 从旧 JSON 数据迁移到 SQLite
├── requirements.txt          # 依赖列表
├── .gitignore
└── README.md
```

## 📊 数据存储

数据存在项目根目录的 `todos.db`（SQLite 数据库），**不会上传到 Git**。

表结构：

```sql
CREATE TABLE todos (
    id        INTEGER PRIMARY KEY AUTOINCREMENT,
    text      TEXT    NOT NULL,
    done      INTEGER NOT NULL DEFAULT 0,
    priority  TEXT    NOT NULL DEFAULT 'mid',
    due       TEXT,
    created   TEXT    NOT NULL DEFAULT (datetime('now'))
);
```

## 🛠️ 开发

### 添加新功能

1. 改 `src/db.py`（如需数据库操作）
2. 改 `src/main.py`（业务逻辑 + CLI）
3. 在 `tests/` 里加测试
4. 跑 `pytest` 确保全过
5. 提交 + 推送，CI 自动验证

### CI/CD

每次推送到 `main` 分支，GitHub Actions 会自动：

- 在 **Ubuntu** 上，用 **Python 3.10 / 3.11 / 3.12** 三个版本
- 安装依赖
- 运行所有测试
- 生成覆盖率报告

## 📄 许可证

MIT

---

如果这个项目对你有帮助，欢迎 ⭐ Star！
