mod.rs

  1mod compact;
  2mod create;
  3mod dep;
  4mod done;
  5mod export;
  6mod import;
  7mod init;
  8mod label;
  9mod list;
 10mod ready;
 11mod reopen;
 12mod search;
 13mod show;
 14mod stats;
 15mod update;
 16
 17use crate::cli::{Cli, Command};
 18use crate::db;
 19use anyhow::Result;
 20
 21fn require_root() -> Result<std::path::PathBuf> {
 22    db::find_root(&std::env::current_dir()?)
 23}
 24
 25pub fn dispatch(cli: &Cli) -> Result<()> {
 26    match &cli.command {
 27        Command::Init { stealth } => {
 28            let root = std::env::current_dir()?;
 29            init::run(&root, *stealth, cli.json)
 30        }
 31        Command::Create {
 32            title,
 33            priority,
 34            task_type,
 35            desc,
 36            parent,
 37            labels,
 38        } => {
 39            let root = require_root()?;
 40            create::run(
 41                &root,
 42                create::Opts {
 43                    title: title.as_deref(),
 44                    priority: *priority,
 45                    task_type,
 46                    desc: desc.as_deref(),
 47                    parent: parent.as_deref(),
 48                    labels: labels.as_deref(),
 49                    json: cli.json,
 50                },
 51            )
 52        }
 53        Command::List {
 54            status,
 55            priority,
 56            label,
 57        } => {
 58            let root = require_root()?;
 59            list::run(
 60                &root,
 61                status.as_deref(),
 62                *priority,
 63                label.as_deref(),
 64                cli.json,
 65            )
 66        }
 67        Command::Show { id } => {
 68            let root = require_root()?;
 69            show::run(&root, id, cli.json)
 70        }
 71        Command::Update {
 72            id,
 73            status,
 74            priority,
 75            title,
 76            desc,
 77        } => {
 78            let root = require_root()?;
 79            update::run(
 80                &root,
 81                id,
 82                update::Opts {
 83                    status: status.as_deref(),
 84                    priority: *priority,
 85                    title: title.as_deref(),
 86                    desc: desc.as_deref(),
 87                    json: cli.json,
 88                },
 89            )
 90        }
 91        Command::Done { ids } => {
 92            let root = require_root()?;
 93            done::run(&root, ids, cli.json)
 94        }
 95        Command::Reopen { ids } => {
 96            let root = require_root()?;
 97            reopen::run(&root, ids, cli.json)
 98        }
 99        Command::Dep { action } => {
100            let root = require_root()?;
101            dep::run(&root, action, cli.json)
102        }
103        Command::Label { action } => {
104            let root = require_root()?;
105            label::run(&root, action, cli.json)
106        }
107        Command::Search { query } => {
108            let root = require_root()?;
109            search::run(&root, query, cli.json)
110        }
111        Command::Ready => {
112            let root = require_root()?;
113            ready::run(&root, cli.json)
114        }
115        Command::Stats => {
116            let root = require_root()?;
117            stats::run(&root)
118        }
119        Command::Compact => {
120            let root = require_root()?;
121            compact::run(&root)
122        }
123        Command::Export => {
124            let root = require_root()?;
125            export::run(&root)
126        }
127        Command::Import { file } => {
128            let root = require_root()?;
129            import::run(&root, file)
130        }
131    }
132}