1mod assets;
9mod checklists;
10mod submittals;
11
12use anyhow::Result;
13use clap::Subcommand;
14use std::path::PathBuf;
15
16use crate::output::OutputFormat;
17use raps_acc::AccClient;
18
19#[derive(Debug, Subcommand)]
20pub enum AccCommands {
21 #[command(subcommand)]
23 Asset(AssetCommands),
24
25 #[command(subcommand)]
27 Submittal(SubmittalCommands),
28
29 #[command(subcommand)]
31 Checklist(ChecklistCommands),
32}
33
34#[derive(Debug, Subcommand)]
35pub enum AssetCommands {
36 List {
38 project_id: String,
40 },
41
42 Get {
44 project_id: String,
46 asset_id: String,
48 },
49
50 Create {
52 project_id: String,
54 #[arg(long)]
56 description: Option<String>,
57 #[arg(long)]
59 barcode: Option<String>,
60 #[arg(long)]
62 category_id: Option<String>,
63 },
64
65 Update {
67 project_id: String,
69 asset_id: String,
71 #[arg(long)]
73 description: Option<String>,
74 #[arg(long)]
76 barcode: Option<String>,
77 #[arg(long)]
79 status_id: Option<String>,
80 },
81
82 Delete {
84 project_id: String,
86 asset_id: String,
88 },
89}
90
91#[derive(Debug, Subcommand)]
92pub enum SubmittalCommands {
93 List {
95 project_id: String,
97 },
98
99 Get {
101 project_id: String,
103 submittal_id: String,
105 },
106
107 Create {
109 project_id: String,
111 #[arg(long)]
113 title: Option<String>,
114 #[arg(long)]
116 spec_section: Option<String>,
117 #[arg(long)]
119 due_date: Option<String>,
120 #[arg(long, value_name = "FILE")]
122 from_csv: Option<PathBuf>,
123 },
124
125 Update {
127 project_id: String,
129 submittal_id: String,
131 #[arg(long)]
133 title: Option<String>,
134 #[arg(long)]
136 status: Option<String>,
137 #[arg(long)]
139 due_date: Option<String>,
140 },
141
142 Delete {
144 project_id: String,
146 submittal_id: String,
148 },
149}
150
151#[derive(Debug, Subcommand)]
152pub enum ChecklistCommands {
153 List {
155 project_id: String,
157 },
158
159 Get {
161 project_id: String,
163 checklist_id: String,
165 },
166
167 Create {
169 project_id: String,
171 #[arg(long)]
173 title: String,
174 #[arg(long)]
176 template_id: Option<String>,
177 #[arg(long)]
179 location: Option<String>,
180 #[arg(long)]
182 due_date: Option<String>,
183 #[arg(long)]
185 assignee_id: Option<String>,
186 },
187
188 Update {
190 project_id: String,
192 checklist_id: String,
194 #[arg(long)]
196 title: Option<String>,
197 #[arg(long)]
199 status: Option<String>,
200 #[arg(long)]
202 location: Option<String>,
203 #[arg(long)]
205 due_date: Option<String>,
206 },
207
208 Templates {
210 project_id: String,
212 },
213}
214
215pub(super) fn truncate_str(s: &str, max_len: usize) -> String {
220 if s.len() <= max_len {
221 s.to_string()
222 } else {
223 format!("{}...", &s[..max_len - 3])
224 }
225}
226
227impl AccCommands {
232 pub async fn execute(self, client: &AccClient, output_format: OutputFormat) -> Result<()> {
233 match self {
234 AccCommands::Asset(cmd) => cmd.execute(client, output_format).await,
235 AccCommands::Submittal(cmd) => cmd.execute(client, output_format).await,
236 AccCommands::Checklist(cmd) => cmd.execute(client, output_format).await,
237 }
238 }
239}
240
241impl AssetCommands {
242 pub async fn execute(self, client: &AccClient, output_format: OutputFormat) -> Result<()> {
243 match self {
244 AssetCommands::List { project_id } => {
245 assets::list_assets(client, &project_id, output_format).await
246 }
247 AssetCommands::Get {
248 project_id,
249 asset_id,
250 } => assets::get_asset(client, &project_id, &asset_id, output_format).await,
251 AssetCommands::Create {
252 project_id,
253 description,
254 barcode,
255 category_id,
256 } => {
257 assets::create_asset(
258 client,
259 &project_id,
260 description,
261 barcode,
262 category_id,
263 output_format,
264 )
265 .await
266 }
267 AssetCommands::Update {
268 project_id,
269 asset_id,
270 description,
271 barcode,
272 status_id,
273 } => {
274 assets::update_asset(
275 client,
276 &project_id,
277 &asset_id,
278 description,
279 barcode,
280 status_id,
281 output_format,
282 )
283 .await
284 }
285 AssetCommands::Delete {
286 project_id,
287 asset_id,
288 } => assets::delete_asset(client, &project_id, &asset_id, output_format).await,
289 }
290 }
291}
292
293impl SubmittalCommands {
294 pub async fn execute(self, client: &AccClient, output_format: OutputFormat) -> Result<()> {
295 match self {
296 SubmittalCommands::List { project_id } => {
297 submittals::list_submittals(client, &project_id, output_format).await
298 }
299 SubmittalCommands::Get {
300 project_id,
301 submittal_id,
302 } => submittals::get_submittal(client, &project_id, &submittal_id, output_format).await,
303 SubmittalCommands::Create {
304 project_id,
305 title,
306 spec_section,
307 due_date,
308 from_csv,
309 } => {
310 submittals::create_submittal(
311 client,
312 &project_id,
313 title,
314 spec_section,
315 due_date,
316 from_csv,
317 output_format,
318 )
319 .await
320 }
321 SubmittalCommands::Update {
322 project_id,
323 submittal_id,
324 title,
325 status,
326 due_date,
327 } => {
328 submittals::update_submittal(
329 client,
330 &project_id,
331 &submittal_id,
332 title,
333 status,
334 due_date,
335 output_format,
336 )
337 .await
338 }
339 SubmittalCommands::Delete {
340 project_id,
341 submittal_id,
342 } => {
343 submittals::delete_submittal(client, &project_id, &submittal_id, output_format)
344 .await
345 }
346 }
347 }
348}
349
350impl ChecklistCommands {
351 pub async fn execute(self, client: &AccClient, output_format: OutputFormat) -> Result<()> {
352 match self {
353 ChecklistCommands::List { project_id } => {
354 checklists::list_checklists(client, &project_id, output_format).await
355 }
356 ChecklistCommands::Get {
357 project_id,
358 checklist_id,
359 } => checklists::get_checklist(client, &project_id, &checklist_id, output_format).await,
360 ChecklistCommands::Create {
361 project_id,
362 title,
363 template_id,
364 location,
365 due_date,
366 assignee_id,
367 } => {
368 checklists::create_checklist(
369 client,
370 &project_id,
371 &title,
372 template_id,
373 location,
374 due_date,
375 assignee_id,
376 output_format,
377 )
378 .await
379 }
380 ChecklistCommands::Update {
381 project_id,
382 checklist_id,
383 title,
384 status,
385 location,
386 due_date,
387 } => {
388 checklists::update_checklist(
389 client,
390 &project_id,
391 &checklist_id,
392 title,
393 status,
394 location,
395 due_date,
396 output_format,
397 )
398 .await
399 }
400 ChecklistCommands::Templates { project_id } => {
401 checklists::list_templates(client, &project_id, output_format).await
402 }
403 }
404 }
405}