Skip to main content

codex_wrapper/command/
version.rs

1use crate::Codex;
2use crate::command::CodexCommand;
3use crate::error::Result;
4use crate::exec::{self, CommandOutput};
5
6/// Print the codex version string (`codex --version`).
7///
8/// # Example
9///
10/// ```no_run
11/// use codex_wrapper::{Codex, CodexCommand, VersionCommand};
12///
13/// # async fn example() -> codex_wrapper::Result<()> {
14/// let codex = Codex::builder().build()?;
15/// let output = VersionCommand::new().execute(&codex).await?;
16/// println!("{}", output.stdout);
17/// # Ok(())
18/// # }
19/// ```
20#[derive(Debug, Clone, Default)]
21pub struct VersionCommand;
22
23impl VersionCommand {
24    /// Create a new version command.
25    #[must_use]
26    pub fn new() -> Self {
27        Self
28    }
29}
30
31impl CodexCommand for VersionCommand {
32    type Output = CommandOutput;
33
34    fn args(&self) -> Vec<String> {
35        vec!["--version".to_string()]
36    }
37
38    async fn execute(&self, codex: &Codex) -> Result<CommandOutput> {
39        exec::run_codex(codex, self.args()).await
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn version_args() {
49        assert_eq!(VersionCommand::new().args(), vec!["--version"]);
50    }
51}