Skip to main content

claude_wrapper/command/
doctor.rs

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