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