1use std::ffi::OsString;
2
3use crate::{
4 ApplyDiffArtifacts, CodexClient, CodexError, ExecReviewCommandRequest, ReviewCommandRequest,
5};
6
7impl CodexClient {
8 pub async fn review(
10 &self,
11 request: ReviewCommandRequest,
12 ) -> Result<ApplyDiffArtifacts, CodexError> {
13 if matches!(request.prompt.as_deref(), Some(prompt) if prompt.trim().is_empty()) {
14 return Err(CodexError::EmptyPrompt);
15 }
16
17 let mut args = vec![OsString::from("review")];
18 if let Some(base) = request.base {
19 if !base.trim().is_empty() {
20 args.push(OsString::from("--base"));
21 args.push(OsString::from(base));
22 }
23 }
24 if let Some(commit) = request.commit {
25 if !commit.trim().is_empty() {
26 args.push(OsString::from("--commit"));
27 args.push(OsString::from(commit));
28 }
29 }
30 if let Some(title) = request.title {
31 if !title.trim().is_empty() {
32 args.push(OsString::from("--title"));
33 args.push(OsString::from(title));
34 }
35 }
36 if request.uncommitted {
37 args.push(OsString::from("--uncommitted"));
38 }
39 if let Some(prompt) = request.prompt {
40 if !prompt.trim().is_empty() {
41 args.push(OsString::from(prompt));
42 }
43 }
44
45 self.run_simple_command_with_overrides(args, request.overrides)
46 .await
47 }
48
49 pub async fn exec_review(
51 &self,
52 request: ExecReviewCommandRequest,
53 ) -> Result<ApplyDiffArtifacts, CodexError> {
54 if matches!(request.prompt.as_deref(), Some(prompt) if prompt.trim().is_empty()) {
55 return Err(CodexError::EmptyPrompt);
56 }
57
58 let ExecReviewCommandRequest {
59 prompt,
60 base,
61 commit,
62 title,
63 uncommitted,
64 ephemeral,
65 ignore_rules,
66 ignore_user_config,
67 json,
68 output_last_message,
69 skip_git_repo_check,
70 overrides,
71 } = request;
72
73 let mut args = vec![OsString::from("exec"), OsString::from("review")];
74 if let Some(base) = base {
75 if !base.trim().is_empty() {
76 args.push(OsString::from("--base"));
77 args.push(OsString::from(base));
78 }
79 }
80 if let Some(commit) = commit {
81 if !commit.trim().is_empty() {
82 args.push(OsString::from("--commit"));
83 args.push(OsString::from(commit));
84 }
85 }
86 if ephemeral {
87 args.push(OsString::from("--ephemeral"));
88 }
89 if ignore_rules {
90 args.push(OsString::from("--ignore-rules"));
91 }
92 if ignore_user_config {
93 args.push(OsString::from("--ignore-user-config"));
94 }
95 if json {
96 args.push(OsString::from("--json"));
97 }
98 if let Some(output_last_message) = output_last_message {
99 args.push(OsString::from("--output-last-message"));
100 args.push(output_last_message.into_os_string());
101 }
102 if skip_git_repo_check {
103 args.push(OsString::from("--skip-git-repo-check"));
104 }
105 if let Some(title) = title {
106 if !title.trim().is_empty() {
107 args.push(OsString::from("--title"));
108 args.push(OsString::from(title));
109 }
110 }
111 if uncommitted {
112 args.push(OsString::from("--uncommitted"));
113 }
114 if let Some(prompt) = prompt {
115 if !prompt.trim().is_empty() {
116 args.push(OsString::from(prompt));
117 }
118 }
119
120 self.run_simple_command_with_overrides(args, overrides)
121 .await
122 }
123}