Skip to main content

claude_wrapper/command/
agents.rs

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