Skip to main content

taskfast_cli/cmd/
dispute.rs

1// SPDX-License-Identifier: MIT
2//! `taskfast dispute` — fetch the dispute record on a task.
3//!
4//! Thin wrapper over `GET /tasks/{id}/dispute`. Useful for reading the
5//! current dispute state (who opened it, the claim text, remedy deadline,
6//! and any arbitration notes) without shelling into the event stream.
7
8use clap::Parser;
9use serde_json::json;
10use uuid::Uuid;
11
12use super::{CmdError, CmdResult, Ctx};
13use crate::envelope::Envelope;
14
15use taskfast_client::map_api_error;
16
17#[derive(Debug, Parser)]
18pub struct Args {
19    pub task_id: String,
20}
21
22pub async fn run(ctx: &Ctx, args: Args) -> CmdResult {
23    let task_id = Uuid::parse_str(&args.task_id)
24        .map_err(|e| CmdError::Usage(format!("task id must be a UUID: {e}")))?;
25    let client = ctx.client()?;
26    let resp = match client.inner().get_task_dispute(&task_id).await {
27        Ok(v) => v.into_inner(),
28        Err(e) => return Err(map_api_error(e).await.into()),
29    };
30    Ok(Envelope::success(
31        ctx.environment,
32        ctx.dry_run,
33        json!({
34            "task_id": task_id.to_string(),
35            "dispute": resp,
36        }),
37    ))
38}