claude_wrapper/command/
agents.rs1use crate::Claude;
2use crate::command::ClaudeCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6#[derive(Debug, Clone, Default)]
24pub struct AgentsCommand {
25 setting_sources: Option<String>,
26 json: bool,
27}
28
29impl AgentsCommand {
30 #[must_use]
31 pub fn new() -> Self {
32 Self::default()
33 }
34
35 #[must_use]
37 pub fn setting_sources(mut self, sources: impl Into<String>) -> Self {
38 self.setting_sources = Some(sources.into());
39 self
40 }
41
42 #[must_use]
44 pub fn json(mut self) -> Self {
45 self.json = true;
46 self
47 }
48}
49
50impl ClaudeCommand for AgentsCommand {
51 type Output = CommandOutput;
52
53 fn args(&self) -> Vec<String> {
54 let mut args = vec!["agents".to_string()];
55 if self.json {
56 args.push("--json".to_string());
57 }
58 if let Some(ref sources) = self.setting_sources {
59 args.push("--setting-sources".to_string());
60 args.push(sources.clone());
61 }
62 args
63 }
64
65 async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
66 exec::run_claude(claude, self.args()).await
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73 use crate::command::ClaudeCommand;
74
75 #[test]
76 fn test_agents_default() {
77 let cmd = AgentsCommand::new();
78 assert_eq!(ClaudeCommand::args(&cmd), vec!["agents"]);
79 }
80
81 #[test]
82 fn test_agents_with_sources() {
83 let cmd = AgentsCommand::new().setting_sources("user,project");
84 assert_eq!(
85 ClaudeCommand::args(&cmd),
86 vec!["agents", "--setting-sources", "user,project"]
87 );
88 }
89
90 #[test]
91 fn test_agents_json_flag() {
92 let cmd = AgentsCommand::new().json();
93 assert_eq!(ClaudeCommand::args(&cmd), vec!["agents", "--json"]);
94 }
95}