1use anyhow::Result;
2use std::path::Path;
3
4use crate::db;
5
6pub fn run(root: &Path, ids: &[String], json: bool) -> Result<()> {
7 let conn = db::open(root)?;
8 let ts = db::now_utc();
9
10 let c = crate::color::stdout_theme();
11 for id in ids {
12 conn.execute(
13 "UPDATE tasks SET status = 'closed', updated = ?1 WHERE id = ?2",
14 rusqlite::params![ts, id],
15 )?;
16 if !json {
17 println!("{}closed{} {id}", c.green, c.reset);
18 }
19 }
20
21 if json {
22 let details: Vec<serde_json::Value> = ids
23 .iter()
24 .map(|id| {
25 Ok(serde_json::json!({
26 "id": id,
27 "status": "closed",
28 }))
29 })
30 .collect::<Result<_>>()?;
31 println!("{}", serde_json::to_string(&details)?);
32 }
33
34 Ok(())
35}