Skip to main content

claude_wrapper/command/
agents.rs

1use crate::Claude;
2use crate::command::ClaudeCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6/// List configured agents.
7///
8/// # Example
9///
10/// ```no_run
11/// use claude_wrapper::{Claude, ClaudeCommand, AgentsCommand};
12///
13/// # async fn example() -> claude_wrapper::Result<()> {
14/// let claude = Claude::builder().build()?;
15/// let output = AgentsCommand::new()
16///     .setting_sources("user,project")
17///     .execute(&claude)
18///     .await?;
19/// println!("{}", output.stdout);
20/// # Ok(())
21/// # }
22/// ```
23#[derive(Debug, Clone, Default)]
24pub struct AgentsCommand {
25    setting_sources: Option<String>,
26}
27
28impl AgentsCommand {
29    #[must_use]
30    pub fn new() -> Self {
31        Self::default()
32    }
33
34    /// Set which setting sources to load (comma-separated: user, project, local).
35    #[must_use]
36    pub fn setting_sources(mut self, sources: impl Into<String>) -> Self {
37        self.setting_sources = Some(sources.into());
38        self
39    }
40}
41
42impl ClaudeCommand for AgentsCommand {
43    type Output = CommandOutput;
44
45    fn args(&self) -> Vec<String> {
46        let mut args = vec!["agents".to_string()];
47        if let Some(ref sources) = self.setting_sources {
48            args.push("--setting-sources".to_string());
49            args.push(sources.clone());
50        }
51        args
52    }
53
54    async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
55        exec::run_claude(claude, self.args()).await
56    }
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62    use crate::command::ClaudeCommand;
63
64    #[test]
65    fn test_agents_default() {
66        let cmd = AgentsCommand::new();
67        assert_eq!(ClaudeCommand::args(&cmd), vec!["agents"]);
68    }
69
70    #[test]
71    fn test_agents_with_sources() {
72        let cmd = AgentsCommand::new().setting_sources("user,project");
73        assert_eq!(
74            ClaudeCommand::args(&cmd),
75            vec!["agents", "--setting-sources", "user,project"]
76        );
77    }
78}