feat: add bulk option to todo done

This commit is contained in:
2026-03-01 11:07:07 +01:00
parent fcc14ce284
commit abffaa8ef9
3 changed files with 25 additions and 12 deletions

View File

@@ -86,8 +86,9 @@ pub struct ListArgs {
#[derive(Args)] #[derive(Args)]
pub struct DoneArgs { pub struct DoneArgs {
/// todo id /// todo id(s)
pub id: i64, #[arg(required = true)]
pub id: Vec<i64>,
} }
#[derive(Args)] #[derive(Args)]

View File

@@ -65,9 +65,11 @@ async fn list(ctx: &Ctx<'_>, args: ListArgs) -> Result<()> {
} }
async fn done(ctx: &Ctx<'_>, args: DoneArgs) -> Result<()> { async fn done(ctx: &Ctx<'_>, args: DoneArgs) -> Result<()> {
let todo = db::complete_todo(ctx.pool, args.id).await?; for id in args.id {
print!("{} ", "done:".green().bold()); let todo = db::complete_todo(ctx.pool, id).await?;
print_todo(&todo); print!("{} ", "done:".green().bold());
print_todo(&todo);
}
Ok(()) Ok(())
} }

View File

@@ -79,9 +79,9 @@ fn tool_schemas() -> Value {
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": { "type": "integer" } "id": { "type": "integer", "description": "single todo id" },
}, "ids": { "type": "array", "items": { "type": "integer" }, "description": "multiple todo ids" }
"required": ["id"] }
} }
}, },
{ {
@@ -182,11 +182,21 @@ async fn dispatch(pool: &Pool, name: &str, args: &Value) -> Value {
.map(|t| serde_json::to_string(&t).unwrap()) .map(|t| serde_json::to_string(&t).unwrap())
} }
"todo_done" => { "todo_done" => {
let id = match args.get("id").and_then(|v| v.as_i64()) { let ids: Vec<i64> = if let Some(arr) = args.get("ids").and_then(|v| v.as_array()) {
Some(id) => id, arr.iter().filter_map(|v| v.as_i64()).collect()
None => return tool_error("missing required arg: id".into()), } else if let Some(id) = args.get("id").and_then(|v| v.as_i64()) {
vec![id]
} else {
return tool_error("missing required arg: id or ids".into());
}; };
db::complete_todo(pool, id).await.map(|t| serde_json::to_string(&t).unwrap()) let mut todos = Vec::new();
for id in ids {
match db::complete_todo(pool, id).await {
Ok(t) => todos.push(t),
Err(e) => return tool_error(e.to_string()),
}
}
Ok(serde_json::to_string(&todos).unwrap())
} }
"todo_edit" => { "todo_edit" => {
let id = match args.get("id").and_then(|v| v.as_i64()) { let id = match args.get("id").and_then(|v| v.as_i64()) {