1use std::path::PathBuf;
27
28use clap::{Parser, Subcommand, ValueEnum};
29use serde_json::json;
30use uuid::Uuid;
31
32use super::{CmdError, CmdResult, Ctx};
33use crate::envelope::Envelope;
34
35use taskfast_client::api::types::{
36 CompletionSubmission, DisputeRequest, ListMyTasksStatus, ReassignTaskBody, TaskEditRequest,
37};
38use taskfast_client::map_api_error;
39use taskfast_client::TaskFastClient;
40
41#[derive(Debug, Subcommand)]
42pub enum Command {
43 List(ListArgs),
45 Get(GetArgs),
47 Submit(SubmitArgs),
49 Approve(ApproveArgs),
51 Dispute(DisputeArgs),
53 Cancel(CancelArgs),
55 Claim(IdOnlyArgs),
57 Refuse(IdOnlyArgs),
59 Remedy(SubmitArgs),
61 Concede(IdOnlyArgs),
63 Abort(IdOnlyArgs),
65 Bids(BidsArgs),
67 Reassign(ReassignArgs),
69 Reopen(IdOnlyArgs),
71 Open(IdOnlyArgs),
73 Edit(EditArgs),
75}
76
77#[derive(Debug, Parser)]
78pub struct ReassignArgs {
79 pub id: String,
81
82 #[arg(long)]
84 pub agent_id: String,
85}
86
87#[derive(Debug, Parser)]
88pub struct EditArgs {
89 pub id: String,
91
92 #[arg(long)]
93 pub title: Option<String>,
94
95 #[arg(long)]
96 pub description: Option<String>,
97
98 #[arg(long)]
100 pub budget_max: Option<String>,
101
102 #[arg(long)]
103 pub review_window_hours: Option<i64>,
104
105 #[arg(long)]
106 pub remedy_window_hours: Option<i64>,
107}
108
109#[derive(Debug, Parser)]
110pub struct ListArgs {
111 #[arg(long, default_value = "mine")]
113 pub kind: ListKind,
114
115 #[arg(long)]
121 pub status: Option<TaskStatus>,
122
123 #[arg(long)]
125 pub cursor: Option<String>,
126
127 #[arg(long, default_value_t = 20)]
130 pub limit: i64,
131}
132
133#[derive(Debug, Parser)]
134pub struct GetArgs {
135 pub id: String,
137}
138
139#[derive(Debug, Parser)]
143pub struct IdOnlyArgs {
144 pub id: String,
146}
147
148#[derive(Debug, Parser)]
149pub struct BidsArgs {
150 pub id: String,
152
153 #[arg(long)]
155 pub cursor: Option<String>,
156
157 #[arg(long, default_value_t = 20)]
159 pub limit: i64,
160}
161
162#[derive(Debug, Parser)]
163pub struct ApproveArgs {
164 pub id: String,
166}
167
168#[derive(Debug, Parser)]
169pub struct DisputeArgs {
170 pub id: String,
172
173 #[arg(long)]
176 pub reason: String,
177}
178
179#[derive(Debug, Parser)]
180pub struct CancelArgs {
181 pub id: String,
183}
184
185#[derive(Debug, Parser)]
186pub struct SubmitArgs {
187 pub id: String,
189
190 #[arg(long)]
192 pub summary: String,
193
194 #[arg(long)]
198 pub artifact: Vec<PathBuf>,
199}
200
201#[derive(Debug, Clone, Copy, ValueEnum)]
202pub enum ListKind {
203 Mine,
205 Queue,
207 Posted,
209}
210
211#[derive(Debug, Clone, Copy, ValueEnum)]
218pub enum TaskStatus {
219 InProgress,
220 UnderReview,
221 Disputed,
222 Remedied,
223 Assigned,
224 All,
225}
226
227impl From<TaskStatus> for ListMyTasksStatus {
228 fn from(s: TaskStatus) -> Self {
229 match s {
230 TaskStatus::InProgress => Self::InProgress,
231 TaskStatus::UnderReview => Self::UnderReview,
232 TaskStatus::Disputed => Self::Disputed,
233 TaskStatus::Remedied => Self::Remedied,
234 TaskStatus::Assigned => Self::Assigned,
235 TaskStatus::All => Self::All,
236 }
237 }
238}
239
240pub async fn run(ctx: &Ctx, cmd: Command) -> CmdResult {
241 match cmd {
242 Command::List(args) => list(ctx, args).await,
243 Command::Get(args) => get(ctx, args).await,
244 Command::Submit(args) => submit(ctx, args, SubmitKind::Completion).await,
245 Command::Approve(args) => approve(ctx, args).await,
246 Command::Dispute(args) => dispute(ctx, args).await,
247 Command::Cancel(args) => cancel(ctx, args).await,
248 Command::Claim(args) => claim(ctx, args).await,
249 Command::Refuse(args) => refuse(ctx, args).await,
250 Command::Remedy(args) => submit(ctx, args, SubmitKind::Remedy).await,
251 Command::Concede(args) => concede(ctx, args).await,
252 Command::Abort(args) => abort(ctx, args).await,
253 Command::Bids(args) => bids(ctx, args).await,
254 Command::Reassign(args) => reassign(ctx, args).await,
255 Command::Reopen(args) => reopen(ctx, args).await,
256 Command::Open(args) => open(ctx, args).await,
257 Command::Edit(args) => edit(ctx, args).await,
258 }
259}
260
261#[derive(Debug, Clone, Copy)]
265enum SubmitKind {
266 Completion,
267 Remedy,
268}
269
270async fn approve(ctx: &Ctx, args: ApproveArgs) -> CmdResult {
271 let task_id = Uuid::parse_str(&args.id)
272 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
273 if ctx.dry_run {
274 return Ok(Envelope::success(
275 ctx.environment,
276 ctx.dry_run,
277 json!({
278 "action": "would_approve",
279 "task_id": task_id.to_string(),
280 }),
281 ));
282 }
283 let client = ctx.client()?;
284 let resp = match client.inner().approve_task(&task_id).await {
285 Ok(v) => v.into_inner(),
286 Err(e) => return Err(map_api_error(e).await.into()),
287 };
288 Ok(Envelope::success(
289 ctx.environment,
290 ctx.dry_run,
291 json!({
292 "task_id": resp.task_id,
293 "status": resp.status,
294 }),
295 ))
296}
297
298async fn dispute(ctx: &Ctx, args: DisputeArgs) -> CmdResult {
299 let task_id = Uuid::parse_str(&args.id)
300 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
301 if args.reason.trim().is_empty() {
304 return Err(CmdError::Usage("--reason must not be empty".into()));
305 }
306 if ctx.dry_run {
307 return Ok(Envelope::success(
308 ctx.environment,
309 ctx.dry_run,
310 json!({
311 "action": "would_dispute",
312 "task_id": task_id.to_string(),
313 "reason": args.reason,
314 }),
315 ));
316 }
317 let client = ctx.client()?;
318 let body = DisputeRequest {
319 reason: args.reason.clone(),
320 };
321 let resp = match client.inner().raise_dispute(&task_id, &body).await {
322 Ok(v) => v.into_inner(),
323 Err(e) => return Err(map_api_error(e).await.into()),
324 };
325 Ok(Envelope::success(
326 ctx.environment,
327 ctx.dry_run,
328 json!({
329 "task_id": resp.task_id,
330 "status": resp.status,
331 "dispute": resp.dispute,
332 "message": resp.message,
333 }),
334 ))
335}
336
337async fn cancel(ctx: &Ctx, args: CancelArgs) -> CmdResult {
338 let task_id = Uuid::parse_str(&args.id)
339 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
340 if ctx.dry_run {
341 return Ok(Envelope::success(
342 ctx.environment,
343 ctx.dry_run,
344 json!({
345 "action": "would_cancel",
346 "task_id": task_id.to_string(),
347 }),
348 ));
349 }
350 let client = ctx.client()?;
351 let resp = match client.inner().cancel_task(&task_id).await {
352 Ok(v) => v.into_inner(),
353 Err(e) => return Err(map_api_error(e).await.into()),
354 };
355 Ok(Envelope::success(
356 ctx.environment,
357 ctx.dry_run,
358 json!({
359 "id": resp.id,
360 "status": resp.status,
361 }),
362 ))
363}
364
365async fn submit(ctx: &Ctx, args: SubmitArgs, kind: SubmitKind) -> CmdResult {
366 let task_id = Uuid::parse_str(&args.id)
368 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
369
370 let resolved: Vec<ResolvedArtifact> = args
373 .artifact
374 .iter()
375 .map(|p| ResolvedArtifact::from_path(p))
376 .collect::<Result<_, _>>()?;
377
378 let action = match kind {
379 SubmitKind::Completion => "would_submit",
380 SubmitKind::Remedy => "would_remedy",
381 };
382
383 if ctx.dry_run {
384 return Ok(Envelope::success(
385 ctx.environment,
386 ctx.dry_run,
387 json!({
388 "action": action,
389 "task_id": task_id.to_string(),
390 "summary": args.summary,
391 "artifacts": resolved.iter().map(|r| r.display_path()).collect::<Vec<_>>(),
392 }),
393 ));
394 }
395
396 let client = ctx.client()?;
397
398 let mut artifact_ids: Vec<uuid::Uuid> = Vec::with_capacity(resolved.len());
401 let mut uploaded_meta: Vec<serde_json::Value> = Vec::with_capacity(resolved.len());
402 for r in resolved {
403 let bytes = std::fs::read(&r.path)
404 .map_err(|e| CmdError::Usage(format!("read {}: {e}", r.path.display())))?;
405 let artifact = client
406 .upload_artifact(&task_id, r.filename.clone(), r.content_type.clone(), bytes)
407 .await
408 .map_err(CmdError::from)?;
409 artifact_ids.push(artifact.id);
410 uploaded_meta.push(json!({
411 "id": artifact.id,
412 "filename": artifact.filename,
413 "content_type": artifact.content_type,
414 "size_bytes": artifact.size_bytes,
415 }));
416 }
417
418 let body = CompletionSubmission {
419 summary: args.summary.clone(),
420 artifact_ids: artifact_ids.clone(),
421 metadata: serde_json::Map::new(),
422 };
423 let result = match kind {
424 SubmitKind::Completion => match client.inner().submit_completion(&task_id, &body).await {
425 Ok(v) => {
426 serde_json::to_value(v.into_inner()).map_err(|e| CmdError::Decode(e.to_string()))?
427 }
428 Err(e) => return Err(map_api_error(e).await.into()),
429 },
430 SubmitKind::Remedy => match client.inner().submit_remedy(&task_id, &body).await {
431 Ok(v) => {
432 serde_json::to_value(v.into_inner()).map_err(|e| CmdError::Decode(e.to_string()))?
433 }
434 Err(e) => return Err(map_api_error(e).await.into()),
435 },
436 };
437
438 Ok(Envelope::success(
439 ctx.environment,
440 ctx.dry_run,
441 json!({
442 "task_id": task_id.to_string(),
443 "artifacts": uploaded_meta,
444 "submission": result,
445 }),
446 ))
447}
448
449async fn claim(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
450 let task_id = Uuid::parse_str(&args.id)
451 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
452 if ctx.dry_run {
453 return Ok(Envelope::success(
454 ctx.environment,
455 ctx.dry_run,
456 json!({ "action": "would_claim", "task_id": task_id.to_string() }),
457 ));
458 }
459 let client = ctx.client()?;
460 let resp = match client.inner().claim_task(&task_id).await {
461 Ok(v) => v.into_inner(),
462 Err(e) => return Err(map_api_error(e).await.into()),
463 };
464 Ok(Envelope::success(
465 ctx.environment,
466 ctx.dry_run,
467 json!({ "claim": resp }),
468 ))
469}
470
471async fn refuse(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
472 let task_id = Uuid::parse_str(&args.id)
473 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
474 if ctx.dry_run {
475 return Ok(Envelope::success(
476 ctx.environment,
477 ctx.dry_run,
478 json!({ "action": "would_refuse", "task_id": task_id.to_string() }),
479 ));
480 }
481 let client = ctx.client()?;
482 let resp = match client.inner().refuse_task(&task_id).await {
483 Ok(v) => v.into_inner(),
484 Err(e) => return Err(map_api_error(e).await.into()),
485 };
486 Ok(Envelope::success(
487 ctx.environment,
488 ctx.dry_run,
489 json!({ "refuse": resp }),
490 ))
491}
492
493async fn concede(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
494 let task_id = Uuid::parse_str(&args.id)
495 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
496 if ctx.dry_run {
497 return Ok(Envelope::success(
498 ctx.environment,
499 ctx.dry_run,
500 json!({ "action": "would_concede", "task_id": task_id.to_string() }),
501 ));
502 }
503 let client = ctx.client()?;
504 let resp = match client.inner().concede_dispute(&task_id).await {
505 Ok(v) => v.into_inner(),
506 Err(e) => return Err(map_api_error(e).await.into()),
507 };
508 Ok(Envelope::success(
509 ctx.environment,
510 ctx.dry_run,
511 json!({ "concede": resp }),
512 ))
513}
514
515async fn abort(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
516 let task_id = Uuid::parse_str(&args.id)
517 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
518 if ctx.dry_run {
519 return Ok(Envelope::success(
520 ctx.environment,
521 ctx.dry_run,
522 json!({ "action": "would_abort", "task_id": task_id.to_string() }),
523 ));
524 }
525 let client = ctx.client()?;
526 let resp = match client.inner().abort_task(&task_id).await {
527 Ok(v) => v.into_inner(),
528 Err(e) => return Err(map_api_error(e).await.into()),
529 };
530 Ok(Envelope::success(
531 ctx.environment,
532 ctx.dry_run,
533 json!({ "abort": resp }),
534 ))
535}
536
537async fn reassign(ctx: &Ctx, args: ReassignArgs) -> CmdResult {
538 let task_id = Uuid::parse_str(&args.id)
539 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
540 let agent_id = Uuid::parse_str(&args.agent_id)
541 .map_err(|e| CmdError::Usage(format!("--agent-id must be a UUID: {e}")))?;
542 if ctx.dry_run {
543 return Ok(Envelope::success(
544 ctx.environment,
545 ctx.dry_run,
546 json!({
547 "action": "would_reassign",
548 "task_id": task_id.to_string(),
549 "agent_id": agent_id.to_string(),
550 }),
551 ));
552 }
553 let client = ctx.client()?;
554 let body = ReassignTaskBody { agent_id };
555 let resp = match client.inner().reassign_task(&task_id, &body).await {
556 Ok(v) => v.into_inner(),
557 Err(e) => return Err(map_api_error(e).await.into()),
558 };
559 Ok(Envelope::success(
560 ctx.environment,
561 ctx.dry_run,
562 json!({ "reassign": resp }),
563 ))
564}
565
566async fn reopen(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
567 let task_id = Uuid::parse_str(&args.id)
568 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
569 if ctx.dry_run {
570 return Ok(Envelope::success(
571 ctx.environment,
572 ctx.dry_run,
573 json!({ "action": "would_reopen", "task_id": task_id.to_string() }),
574 ));
575 }
576 let client = ctx.client()?;
577 let resp = match client.inner().reopen_task(&task_id).await {
578 Ok(v) => v.into_inner(),
579 Err(e) => return Err(map_api_error(e).await.into()),
580 };
581 Ok(Envelope::success(
582 ctx.environment,
583 ctx.dry_run,
584 json!({ "reopen": resp }),
585 ))
586}
587
588async fn open(ctx: &Ctx, args: IdOnlyArgs) -> CmdResult {
589 let task_id = Uuid::parse_str(&args.id)
590 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
591 if ctx.dry_run {
592 return Ok(Envelope::success(
593 ctx.environment,
594 ctx.dry_run,
595 json!({ "action": "would_open", "task_id": task_id.to_string() }),
596 ));
597 }
598 let client = ctx.client()?;
599 let resp = match client.inner().open_task(&task_id).await {
600 Ok(v) => v.into_inner(),
601 Err(e) => return Err(map_api_error(e).await.into()),
602 };
603 Ok(Envelope::success(
604 ctx.environment,
605 ctx.dry_run,
606 json!({ "open": resp }),
607 ))
608}
609
610async fn edit(ctx: &Ctx, args: EditArgs) -> CmdResult {
611 let task_id = Uuid::parse_str(&args.id)
612 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
613 let any_change = args.title.is_some()
615 || args.description.is_some()
616 || args.budget_max.is_some()
617 || args.review_window_hours.is_some()
618 || args.remedy_window_hours.is_some();
619 if !any_change {
620 return Err(CmdError::Usage(
621 "edit requires at least one of --title/--description/--budget-max/--review-window-hours/--remedy-window-hours".into(),
622 ));
623 }
624 let body = TaskEditRequest {
625 title: args.title.clone(),
626 description: args.description.clone(),
627 budget_max: args.budget_max.clone(),
628 review_window_hours: args.review_window_hours,
629 remedy_window_hours: args.remedy_window_hours,
630 completion_criteria: Vec::new(),
631 };
632 if ctx.dry_run {
633 return Ok(Envelope::success(
634 ctx.environment,
635 ctx.dry_run,
636 json!({
637 "action": "would_edit",
638 "task_id": task_id.to_string(),
639 "patch": body,
640 }),
641 ));
642 }
643 let client = ctx.client()?;
644 let resp = match client.inner().edit_task(&task_id, &body).await {
645 Ok(v) => v.into_inner(),
646 Err(e) => return Err(map_api_error(e).await.into()),
647 };
648 Ok(Envelope::success(
649 ctx.environment,
650 ctx.dry_run,
651 json!({ "task": resp }),
652 ))
653}
654
655async fn bids(ctx: &Ctx, args: BidsArgs) -> CmdResult {
656 let task_id = Uuid::parse_str(&args.id)
657 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
658 let client = ctx.client()?;
659 let resp = match client
660 .inner()
661 .list_task_bids(
662 &task_id,
663 args.cursor.as_deref(),
664 taskfast_client::page_limit(args.limit),
665 )
666 .await
667 {
668 Ok(v) => v.into_inner(),
669 Err(e) => return Err(map_api_error(e).await.into()),
670 };
671 Ok(Envelope::success(
672 ctx.environment,
673 ctx.dry_run,
674 json!({
675 "task_id": task_id.to_string(),
676 "bids": resp.data,
677 "meta": resp.meta,
678 }),
679 ))
680}
681
682struct ResolvedArtifact {
685 path: PathBuf,
686 filename: String,
687 content_type: String,
688}
689
690impl ResolvedArtifact {
691 fn from_path(p: &std::path::Path) -> Result<Self, CmdError> {
692 if !p.exists() {
693 return Err(CmdError::Usage(format!(
694 "artifact file not found: {}",
695 p.display()
696 )));
697 }
698 let filename = p
699 .file_name()
700 .and_then(|s| s.to_str())
701 .ok_or_else(|| {
702 CmdError::Usage(format!("artifact path has no filename: {}", p.display()))
703 })?
704 .to_string();
705 let ext = p
706 .extension()
707 .and_then(|s| s.to_str())
708 .map(|s| s.to_ascii_lowercase())
709 .unwrap_or_default();
710 let content_type = content_type_for_ext(&ext).to_string();
711 Ok(Self {
712 path: p.to_path_buf(),
713 filename,
714 content_type,
715 })
716 }
717
718 fn display_path(&self) -> String {
719 self.path.display().to_string()
720 }
721}
722
723pub(super) fn content_type_for_ext(ext: &str) -> &'static str {
728 match ext {
729 "txt" => "text/plain",
730 "md" | "markdown" => "text/plain",
735 "csv" => "text/csv",
736 "json" => "application/json",
737 "xml" => "application/xml",
738 "pdf" => "application/pdf",
739 "doc" => "application/msword",
740 "png" => "image/png",
741 "jpg" | "jpeg" => "image/jpeg",
742 "gif" => "image/gif",
743 "webp" => "image/webp",
744 "svg" => "image/svg+xml",
745 "zip" => "application/zip",
746 "tar" => "application/x-tar",
747 "gz" => "application/gzip",
748 "html" | "htm" => "text/html",
749 "css" => "text/css",
750 "js" => "application/javascript",
751 _ => "application/octet-stream",
752 }
753}
754
755async fn list(ctx: &Ctx, args: ListArgs) -> CmdResult {
756 if args.status.is_some() && !matches!(args.kind, ListKind::Mine) {
757 return Err(CmdError::Usage(
758 "--status is only valid with --kind=mine".into(),
759 ));
760 }
761 let client = ctx.client()?;
762 let data = match args.kind {
763 ListKind::Mine => list_mine(&client, &args).await?,
764 ListKind::Queue => list_queue(&client, &args).await?,
765 ListKind::Posted => list_posted(&client, &args).await?,
766 };
767 Ok(Envelope::success(ctx.environment, ctx.dry_run, data))
768}
769
770const ACTIVE_STATUSES: &[&str] = &[
775 "assigned",
776 "in_progress",
777 "under_review",
778 "disputed",
779 "remedied",
780];
781
782const ACTIVE_FETCH_MULTIPLIER: i64 = 2;
789
790async fn list_mine(
791 client: &TaskFastClient,
792 args: &ListArgs,
793) -> Result<serde_json::Value, CmdError> {
794 let apply_active_filter = args.status.is_none();
795 let status = args.status.map(ListMyTasksStatus::from);
796 let fetch_limit = if apply_active_filter {
797 args.limit.saturating_mul(ACTIVE_FETCH_MULTIPLIER)
798 } else {
799 args.limit
800 };
801 let resp = match client
802 .inner()
803 .list_my_tasks(
804 args.cursor.as_deref(),
805 taskfast_client::page_limit(fetch_limit),
806 status,
807 )
808 .await
809 {
810 Ok(v) => v.into_inner(),
811 Err(e) => return Err(map_api_error(e).await.into()),
812 };
813 let tasks = if apply_active_filter {
814 let limit_usize = usize::try_from(args.limit.max(0)).unwrap_or(usize::MAX);
815 resp.data
816 .into_iter()
817 .filter(|t| ACTIVE_STATUSES.contains(&t.status.as_str()))
818 .take(limit_usize)
819 .collect::<Vec<_>>()
820 } else {
821 resp.data
822 };
823 Ok(json!({
824 "kind": "mine",
825 "tasks": tasks,
826 "meta": resp.meta,
827 }))
828}
829
830async fn list_queue(
831 client: &TaskFastClient,
832 args: &ListArgs,
833) -> Result<serde_json::Value, CmdError> {
834 let resp = match client
835 .inner()
836 .get_agent_queue(
837 args.cursor.as_deref(),
838 taskfast_client::page_limit(args.limit),
839 )
840 .await
841 {
842 Ok(v) => v.into_inner(),
843 Err(e) => return Err(map_api_error(e).await.into()),
844 };
845 Ok(json!({
846 "kind": "queue",
847 "tasks": resp.data,
848 "meta": resp.meta,
849 }))
850}
851
852async fn list_posted(
853 client: &TaskFastClient,
854 args: &ListArgs,
855) -> Result<serde_json::Value, CmdError> {
856 let resp = match client
857 .inner()
858 .get_agent_posted_tasks(
859 args.cursor.as_deref(),
860 taskfast_client::page_limit(args.limit),
861 )
862 .await
863 {
864 Ok(v) => v.into_inner(),
865 Err(e) => return Err(map_api_error(e).await.into()),
866 };
867 Ok(json!({
868 "kind": "posted",
869 "tasks": resp.data,
870 "meta": resp.meta,
871 }))
872}
873
874async fn get(ctx: &Ctx, args: GetArgs) -> CmdResult {
875 let id = Uuid::parse_str(&args.id)
877 .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
878 let client = ctx.client()?;
879 let task = match client.inner().get_task(&id).await {
880 Ok(v) => v.into_inner(),
881 Err(e) => return Err(map_api_error(e).await.into()),
882 };
883 Ok(Envelope::success(
884 ctx.environment,
885 ctx.dry_run,
886 json!({ "task": task }),
887 ))
888}
889
890#[cfg(test)]
891mod tests {
892 use super::*;
893
894 #[test]
895 fn task_status_maps_to_generated_enum() {
896 for (ours, theirs) in [
898 (TaskStatus::InProgress, ListMyTasksStatus::InProgress),
899 (TaskStatus::UnderReview, ListMyTasksStatus::UnderReview),
900 (TaskStatus::Disputed, ListMyTasksStatus::Disputed),
901 (TaskStatus::Remedied, ListMyTasksStatus::Remedied),
902 (TaskStatus::Assigned, ListMyTasksStatus::Assigned),
903 (TaskStatus::All, ListMyTasksStatus::All),
904 ] {
905 assert_eq!(
908 ListMyTasksStatus::from(ours).to_string(),
909 theirs.to_string()
910 );
911 }
912 }
913
914 #[test]
915 fn content_type_maps_markdown_to_text_plain() {
916 assert_eq!(content_type_for_ext("md"), "text/plain");
920 assert_eq!(content_type_for_ext("markdown"), "text/plain");
921 assert_eq!(content_type_for_ext("json"), "application/json");
924 assert_eq!(
925 content_type_for_ext("unknownext"),
926 "application/octet-stream"
927 );
928 }
929}