show.rs

 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!("{}      effort{} = {}", c.bold, c.reset, t.effort);
29        println!("{}        type{} = {}", c.bold, c.reset, t.task_type);
30        if !t.description.is_empty() {
31            println!("{} description{} = {}", c.bold, c.reset, t.description);
32        }
33        println!("{}     created{} = {}", c.bold, c.reset, t.created);
34        println!("{}     updated{} = {}", c.bold, c.reset, t.updated);
35        if !detail.labels.is_empty() {
36            println!(
37                "{}      labels{} = {}",
38                c.bold,
39                c.reset,
40                detail.labels.join(",")
41            );
42        }
43        if !detail.blockers.is_empty() {
44            println!(
45                "{}    blockers{} = {}",
46                c.bold,
47                c.reset,
48                detail.blockers.join(",")
49            );
50        }
51    }
52
53    Ok(())
54}