Skip to main content

codex_wrapper/command/
raw.rs

1use crate::Codex;
2use crate::command::CodexCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6#[derive(Debug, Clone)]
7pub struct RawCommand {
8    command_args: Vec<String>,
9}
10
11impl RawCommand {
12    #[must_use]
13    pub fn new(subcommand: impl Into<String>) -> Self {
14        Self {
15            command_args: vec![subcommand.into()],
16        }
17    }
18
19    #[must_use]
20    pub fn arg(mut self, arg: impl Into<String>) -> Self {
21        self.command_args.push(arg.into());
22        self
23    }
24
25    #[must_use]
26    pub fn args(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self {
27        self.command_args.extend(args.into_iter().map(Into::into));
28        self
29    }
30}
31
32impl CodexCommand for RawCommand {
33    type Output = CommandOutput;
34
35    fn args(&self) -> Vec<String> {
36        self.command_args.clone()
37    }
38
39    async fn execute(&self, codex: &Codex) -> Result<CommandOutput> {
40        exec::run_codex(codex, self.args()).await
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    use crate::command::CodexCommand;
48
49    #[test]
50    fn raw_command_args() {
51        let cmd = RawCommand::new("mcp").args(["list", "--json"]);
52        assert_eq!(CodexCommand::args(&cmd), vec!["mcp", "list", "--json"]);
53    }
54}