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 effort,
36 task_type,
37 desc,
38 parent,
39 labels,
40 } => {
41 let root = require_root()?;
42 create::run(
43 &root,
44 create::Opts {
45 title: title.as_deref(),
46 priority: *priority,
47 effort: *effort,
48 task_type,
49 desc: desc.as_deref(),
50 parent: parent.as_deref(),
51 labels: labels.as_deref(),
52 json: cli.json,
53 },
54 )
55 }
56 Command::List {
57 status,
58 priority,
59 label,
60 } => {
61 let root = require_root()?;
62 list::run(
63 &root,
64 status.as_deref(),
65 *priority,
66 label.as_deref(),
67 cli.json,
68 )
69 }
70 Command::Show { id } => {
71 let root = require_root()?;
72 show::run(&root, id, cli.json)
73 }
74 Command::Update {
75 id,
76 status,
77 priority,
78 title,
79 desc,
80 } => {
81 let root = require_root()?;
82 update::run(
83 &root,
84 id,
85 update::Opts {
86 status: status.as_deref(),
87 priority: *priority,
88 title: title.as_deref(),
89 desc: desc.as_deref(),
90 json: cli.json,
91 },
92 )
93 }
94 Command::Done { ids } => {
95 let root = require_root()?;
96 done::run(&root, ids, cli.json)
97 }
98 Command::Reopen { ids } => {
99 let root = require_root()?;
100 reopen::run(&root, ids, cli.json)
101 }
102 Command::Dep { action } => {
103 let root = require_root()?;
104 dep::run(&root, action, cli.json)
105 }
106 Command::Label { action } => {
107 let root = require_root()?;
108 label::run(&root, action, cli.json)
109 }
110 Command::Search { query } => {
111 let root = require_root()?;
112 search::run(&root, query, cli.json)
113 }
114 Command::Ready => {
115 let root = require_root()?;
116 ready::run(&root, cli.json)
117 }
118 Command::Stats => {
119 let root = require_root()?;
120 stats::run(&root)
121 }
122 Command::Compact => {
123 let root = require_root()?;
124 compact::run(&root)
125 }
126 Command::Export => {
127 let root = require_root()?;
128 export::run(&root)
129 }
130 Command::Import { file } => {
131 let root = require_root()?;
132 import::run(&root, file)
133 }
134 Command::Skill { dir } => skill::run(dir.as_deref()),
135 }
136}