Skip to main content

claude_wrapper/command/
version.rs

1use crate::Claude;
2use crate::command::ClaudeCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6/// Run `claude --version` to get the CLI version.
7///
8/// # Example
9///
10/// ```no_run
11/// use claude_wrapper::{Claude, ClaudeCommand, VersionCommand};
12///
13/// # async fn example() -> claude_wrapper::Result<()> {
14/// let claude = Claude::builder().build()?;
15/// let output = VersionCommand::new().execute(&claude).await?;
16/// println!("claude version: {}", output.stdout.trim());
17/// # Ok(())
18/// # }
19/// ```
20#[derive(Debug, Clone, Default)]
21pub struct VersionCommand;
22
23impl VersionCommand {
24    #[must_use]
25    pub fn new() -> Self {
26        Self
27    }
28}
29
30impl ClaudeCommand for VersionCommand {
31    type Output = CommandOutput;
32
33    fn args(&self) -> Vec<String> {
34        vec!["--version".to_string()]
35    }
36
37    async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
38        exec::run_claude(claude, self.args()).await
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_version_args() {
48        let cmd = VersionCommand::new();
49        assert_eq!(cmd.args(), vec!["--version"]);
50    }
51}