1use anyhow::{bail, Result};
2use std::path::Path;
3
4use crate::db;
5
6pub fn run(root: &Path, id: &str, json: bool) -> Result<()> {
7 let conn = db::open(root)?;
8
9 let exists: bool = conn.query_row("SELECT COUNT(*) FROM tasks WHERE id = ?1", [id], |r| {
10 r.get::<_, i64>(0).map(|n| n > 0)
11 })?;
12
13 if !exists {
14 bail!("task {id} not found");
15 }
16
17 let detail = db::load_task_detail(&conn, id)?;
18
19 if json {
20 println!("{}", serde_json::to_string(&detail)?);
21 } else {
22 let c = crate::color::stdout_theme();
23 let t = &detail.task;
24 println!("{} id{} = {}", c.bold, c.reset, t.id);
25 println!("{} title{} = {}", c.bold, c.reset, t.title);
26 println!("{} status{} = {}", c.bold, c.reset, t.status);
27 println!("{} priority{} = {}", c.bold, c.reset, t.priority);
28 println!("{} type{} = {}", c.bold, c.reset, t.task_type);
29 if !t.description.is_empty() {
30 println!("{} description{} = {}", c.bold, c.reset, t.description);
31 }
32 println!("{} created{} = {}", c.bold, c.reset, t.created);
33 println!("{} updated{} = {}", c.bold, c.reset, t.updated);
34 if !detail.labels.is_empty() {
35 println!(
36 "{} labels{} = {}",
37 c.bold,
38 c.reset,
39 detail.labels.join(",")
40 );
41 }
42 if !detail.blockers.is_empty() {
43 println!(
44 "{} blockers{} = {}",
45 c.bold,
46 c.reset,
47 detail.blockers.join(",")
48 );
49 }
50 }
51
52 Ok(())
53}