Skip to main content

claude_wrapper/command/
update.rs

1//! `claude update` -- check for CLI updates and install if available.
2
3#[cfg(feature = "async")]
4use crate::Claude;
5use crate::command::ClaudeCommand;
6#[cfg(feature = "async")]
7use crate::error::Result;
8#[cfg(feature = "async")]
9use crate::exec;
10use crate::exec::CommandOutput;
11
12/// Run `claude update` (alias `upgrade`).
13///
14/// Checks for updates and installs if available. Takes no options.
15///
16/// # Example
17///
18/// ```no_run
19/// # #[cfg(feature = "async")] {
20/// use claude_wrapper::{Claude, ClaudeCommand, UpdateCommand};
21///
22/// # async fn example() -> claude_wrapper::Result<()> {
23/// let claude = Claude::builder().build()?;
24/// let out = UpdateCommand::new().execute(&claude).await?;
25/// println!("{}", out.stdout);
26/// # Ok(()) }
27/// # }
28/// ```
29#[derive(Debug, Clone, Default)]
30pub struct UpdateCommand;
31
32impl UpdateCommand {
33    #[must_use]
34    pub fn new() -> Self {
35        Self
36    }
37}
38
39impl ClaudeCommand for UpdateCommand {
40    type Output = CommandOutput;
41
42    fn args(&self) -> Vec<String> {
43        vec!["update".to_string()]
44    }
45
46    #[cfg(feature = "async")]
47    async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
48        exec::run_claude(claude, self.args()).await
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn update_command_args() {
58        assert_eq!(ClaudeCommand::args(&UpdateCommand::new()), vec!["update"]);
59    }
60}