Skip to main content

claude_code/commands/
command.rs

1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct ClaudeCommandRequest {
5    pub(crate) path: Vec<String>,
6    pub(crate) args: Vec<String>,
7    pub(crate) stdin: Option<Vec<u8>>,
8    pub(crate) timeout: Option<Duration>,
9}
10
11impl ClaudeCommandRequest {
12    pub fn root() -> Self {
13        Self {
14            path: Vec::new(),
15            args: Vec::new(),
16            stdin: None,
17            timeout: None,
18        }
19    }
20
21    pub fn new(path: impl IntoIterator<Item = impl Into<String>>) -> Self {
22        Self {
23            path: path.into_iter().map(Into::into).collect(),
24            args: Vec::new(),
25            stdin: None,
26            timeout: None,
27        }
28    }
29
30    pub fn arg(mut self, arg: impl Into<String>) -> Self {
31        self.args.push(arg.into());
32        self
33    }
34
35    pub fn args(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self {
36        self.args.extend(args.into_iter().map(Into::into));
37        self
38    }
39
40    pub fn stdin_bytes(mut self, bytes: Vec<u8>) -> Self {
41        self.stdin = Some(bytes);
42        self
43    }
44
45    pub fn timeout(mut self, timeout: Duration) -> Self {
46        self.timeout = Some(timeout);
47        self
48    }
49
50    pub fn argv(&self) -> Vec<String> {
51        let mut out = Vec::new();
52        out.extend(self.path.iter().cloned());
53        out.extend(self.args.iter().cloned());
54        out
55    }
56}