Skip to main content

claude_wrapper/command/
doctor.rs

1use crate::Claude;
2use crate::command::ClaudeCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6/// Run `claude doctor` to check CLI health.
7///
8/// # Example
9///
10/// ```no_run
11/// use claude_wrapper::{Claude, ClaudeCommand, DoctorCommand};
12///
13/// # async fn example() -> claude_wrapper::Result<()> {
14/// let claude = Claude::builder().build()?;
15/// let output = DoctorCommand::new().execute(&claude).await?;
16/// println!("{}", output.stdout);
17/// # Ok(())
18/// # }
19/// ```
20#[derive(Debug, Clone, Default)]
21pub struct DoctorCommand {
22    json: bool,
23}
24
25impl DoctorCommand {
26    #[must_use]
27    pub fn new() -> Self {
28        Self::default()
29    }
30
31    /// Output as JSON.
32    #[must_use]
33    pub fn json(mut self) -> Self {
34        self.json = true;
35        self
36    }
37}
38
39impl ClaudeCommand for DoctorCommand {
40    type Output = CommandOutput;
41
42    fn args(&self) -> Vec<String> {
43        let mut args = vec!["doctor".to_string()];
44        if self.json {
45            args.push("--json".to_string());
46        }
47        args
48    }
49
50    async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
51        exec::run_claude(claude, self.args()).await
52    }
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_doctor_args() {
61        let cmd = DoctorCommand::new();
62        assert_eq!(cmd.args(), vec!["doctor"]);
63    }
64
65    #[test]
66    fn test_doctor_json_flag() {
67        let cmd = DoctorCommand::new().json();
68        assert_eq!(cmd.args(), vec!["doctor", "--json"]);
69    }
70}