claude_wrapper/command/
raw.rs1#[cfg(feature = "async")]
9use crate::Claude;
10use crate::command::ClaudeCommand;
11#[cfg(feature = "async")]
12use crate::error::Result;
13#[cfg(feature = "async")]
14use crate::exec;
15use crate::exec::CommandOutput;
16
17#[derive(Debug, Clone)]
39pub struct RawCommand {
40 command_args: Vec<String>,
41}
42
43impl RawCommand {
44 #[must_use]
46 pub fn new(subcommand: impl Into<String>) -> Self {
47 Self {
48 command_args: vec![subcommand.into()],
49 }
50 }
51
52 #[must_use]
54 pub fn arg(mut self, arg: impl Into<String>) -> Self {
55 self.command_args.push(arg.into());
56 self
57 }
58
59 #[must_use]
61 pub fn args(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self {
62 self.command_args.extend(args.into_iter().map(Into::into));
63 self
64 }
65}
66
67impl ClaudeCommand for RawCommand {
68 type Output = CommandOutput;
69
70 fn args(&self) -> Vec<String> {
71 self.command_args.clone()
72 }
73
74 #[cfg(feature = "async")]
75 async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
76 exec::run_claude(claude, self.args()).await
77 }
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83 use crate::command::ClaudeCommand;
84
85 #[test]
86 fn test_raw_command_args() {
87 let cmd = RawCommand::new("agents")
88 .arg("--setting-sources")
89 .arg("user,project");
90
91 assert_eq!(
92 ClaudeCommand::args(&cmd),
93 vec!["agents", "--setting-sources", "user,project"]
94 );
95 }
96
97 #[test]
98 fn test_raw_command_with_args() {
99 let cmd = RawCommand::new("plugin").args(["list", "--scope", "user"]);
100
101 assert_eq!(
102 ClaudeCommand::args(&cmd),
103 vec!["plugin", "list", "--scope", "user"]
104 );
105 }
106}