codex_wrapper/command/
raw.rs1use crate::Codex;
2use crate::command::CodexCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6#[derive(Debug, Clone)]
29pub struct RawCommand {
30 command_args: Vec<String>,
31}
32
33impl RawCommand {
34 #[must_use]
36 pub fn new(subcommand: impl Into<String>) -> Self {
37 Self {
38 command_args: vec![subcommand.into()],
39 }
40 }
41
42 #[must_use]
44 pub fn arg(mut self, arg: impl Into<String>) -> Self {
45 self.command_args.push(arg.into());
46 self
47 }
48
49 #[must_use]
51 pub fn args(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self {
52 self.command_args.extend(args.into_iter().map(Into::into));
53 self
54 }
55}
56
57impl CodexCommand for RawCommand {
58 type Output = CommandOutput;
59
60 fn args(&self) -> Vec<String> {
61 self.command_args.clone()
62 }
63
64 async fn execute(&self, codex: &Codex) -> Result<CommandOutput> {
65 exec::run_codex(codex, self.args()).await
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72 use crate::command::CodexCommand;
73
74 #[test]
75 fn raw_command_args() {
76 let cmd = RawCommand::new("mcp").args(["list", "--json"]);
77 assert_eq!(CodexCommand::args(&cmd), vec!["mcp", "list", "--json"]);
78 }
79}