claude_wrapper/command/
install.rs1#[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#[derive(Debug, Clone, Default)]
35pub struct InstallCommand {
36 target: Option<String>,
37 force: bool,
38}
39
40impl InstallCommand {
41 #[must_use]
42 pub fn new() -> Self {
43 Self::default()
44 }
45
46 #[must_use]
48 pub fn target(mut self, target: impl Into<String>) -> Self {
49 self.target = Some(target.into());
50 self
51 }
52
53 #[must_use]
55 pub fn force(mut self) -> Self {
56 self.force = true;
57 self
58 }
59}
60
61impl ClaudeCommand for InstallCommand {
62 type Output = CommandOutput;
63
64 fn args(&self) -> Vec<String> {
65 let mut args = vec!["install".to_string()];
66 if self.force {
67 args.push("--force".to_string());
68 }
69 if let Some(ref target) = self.target {
70 args.push(target.clone());
71 }
72 args
73 }
74
75 #[cfg(feature = "async")]
76 async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
77 exec::run_claude(claude, self.args()).await
78 }
79}
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn install_command_defaults() {
87 assert_eq!(ClaudeCommand::args(&InstallCommand::new()), vec!["install"]);
88 }
89
90 #[test]
91 fn install_command_with_target_and_force() {
92 let cmd = InstallCommand::new().target("latest").force();
93 assert_eq!(
94 ClaudeCommand::args(&cmd),
95 vec!["install", "--force", "latest"]
96 );
97 }
98}