1use anyhow::{bail, Result};
2use std::path::Path;
3
4pub fn run(root: &Path, stealth: bool, json: bool) -> Result<()> {
5 let td_dir = crate::db::td_dir(root);
6 if td_dir.exists() {
7 bail!("already initialized");
8 }
9
10 crate::db::init(root)?;
11
12 if stealth {
13 use std::io::Write;
14 let mut f = std::fs::OpenOptions::new()
15 .create(true)
16 .append(true)
17 .open(root.join(".gitignore"))?;
18 writeln!(f, ".td/")?;
19 }
20
21 let c = crate::color::stderr_theme();
22 eprintln!("{}info:{} initialized .td/", c.blue, c.reset);
23 if json {
24 println!(r#"{{"success":true}}"#);
25 }
26
27 Ok(())
28}