Skip to main content

codex/cli/
plugin.rs

1use crate::CliOverridesPatch;
2
3/// Request for `codex plugin`.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct PluginCommandRequest {
6    /// Per-call CLI overrides layered on top of the builder.
7    pub overrides: CliOverridesPatch,
8}
9
10impl PluginCommandRequest {
11    pub fn new() -> Self {
12        Self {
13            overrides: CliOverridesPatch::default(),
14        }
15    }
16
17    /// Replaces the default CLI overrides for this request.
18    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
19        self.overrides = overrides;
20        self
21    }
22}
23
24impl Default for PluginCommandRequest {
25    fn default() -> Self {
26        Self::new()
27    }
28}
29
30/// Request for `codex plugin help [COMMAND]...`.
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct PluginHelpRequest {
33    /// Optional command tokens passed after `help` (variadic).
34    pub command: Vec<String>,
35    /// Per-call CLI overrides layered on top of the builder.
36    pub overrides: CliOverridesPatch,
37}
38
39impl PluginHelpRequest {
40    pub fn new() -> Self {
41        Self {
42            command: Vec::new(),
43            overrides: CliOverridesPatch::default(),
44        }
45    }
46
47    /// Sets the optional `COMMAND` tokens.
48    pub fn command(mut self, command: impl IntoIterator<Item = impl Into<String>>) -> Self {
49        self.command = command.into_iter().map(Into::into).collect();
50        self
51    }
52
53    /// Replaces the default CLI overrides for this request.
54    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
55        self.overrides = overrides;
56        self
57    }
58}
59
60impl Default for PluginHelpRequest {
61    fn default() -> Self {
62        Self::new()
63    }
64}
65
66/// Request for `codex plugin marketplace`.
67#[derive(Clone, Debug, Eq, PartialEq)]
68pub struct PluginMarketplaceCommandRequest {
69    /// Per-call CLI overrides layered on top of the builder.
70    pub overrides: CliOverridesPatch,
71}
72
73impl PluginMarketplaceCommandRequest {
74    pub fn new() -> Self {
75        Self {
76            overrides: CliOverridesPatch::default(),
77        }
78    }
79
80    /// Replaces the default CLI overrides for this request.
81    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
82        self.overrides = overrides;
83        self
84    }
85}
86
87impl Default for PluginMarketplaceCommandRequest {
88    fn default() -> Self {
89        Self::new()
90    }
91}
92
93/// Request for `codex plugin marketplace help [COMMAND]...`.
94#[derive(Clone, Debug, Eq, PartialEq)]
95pub struct PluginMarketplaceHelpRequest {
96    /// Optional command tokens passed after `help` (variadic).
97    pub command: Vec<String>,
98    /// Per-call CLI overrides layered on top of the builder.
99    pub overrides: CliOverridesPatch,
100}
101
102impl PluginMarketplaceHelpRequest {
103    pub fn new() -> Self {
104        Self {
105            command: Vec::new(),
106            overrides: CliOverridesPatch::default(),
107        }
108    }
109
110    /// Sets the optional `COMMAND` tokens.
111    pub fn command(mut self, command: impl IntoIterator<Item = impl Into<String>>) -> Self {
112        self.command = command.into_iter().map(Into::into).collect();
113        self
114    }
115
116    /// Replaces the default CLI overrides for this request.
117    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
118        self.overrides = overrides;
119        self
120    }
121}
122
123impl Default for PluginMarketplaceHelpRequest {
124    fn default() -> Self {
125        Self::new()
126    }
127}
128
129/// Request for `codex plugin marketplace add <SOURCE>`.
130#[derive(Clone, Debug, Eq, PartialEq)]
131pub struct PluginMarketplaceAddRequest {
132    /// Marketplace source to install.
133    pub source: String,
134    /// Optional ref passed via `--ref`.
135    pub source_ref: Option<String>,
136    /// Optional sparse path passed via `--sparse`.
137    pub sparse_path: Option<String>,
138    /// Per-call CLI overrides layered on top of the builder.
139    pub overrides: CliOverridesPatch,
140}
141
142impl PluginMarketplaceAddRequest {
143    pub fn new(source: impl Into<String>) -> Self {
144        Self {
145            source: source.into(),
146            source_ref: None,
147            sparse_path: None,
148            overrides: CliOverridesPatch::default(),
149        }
150    }
151
152    /// Sets the optional `--ref` value.
153    pub fn source_ref(mut self, source_ref: impl Into<String>) -> Self {
154        let source_ref = source_ref.into();
155        self.source_ref = (!source_ref.trim().is_empty()).then_some(source_ref);
156        self
157    }
158
159    /// Sets the optional `--sparse` value.
160    pub fn sparse_path(mut self, sparse_path: impl Into<String>) -> Self {
161        let sparse_path = sparse_path.into();
162        self.sparse_path = (!sparse_path.trim().is_empty()).then_some(sparse_path);
163        self
164    }
165
166    /// Replaces the default CLI overrides for this request.
167    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
168        self.overrides = overrides;
169        self
170    }
171}
172
173/// Request for `codex plugin marketplace remove <MARKETPLACE_NAME>`.
174#[derive(Clone, Debug, Eq, PartialEq)]
175pub struct PluginMarketplaceRemoveRequest {
176    /// Configured marketplace name to remove.
177    pub marketplace_name: String,
178    /// Per-call CLI overrides layered on top of the builder.
179    pub overrides: CliOverridesPatch,
180}
181
182impl PluginMarketplaceRemoveRequest {
183    pub fn new(marketplace_name: impl Into<String>) -> Self {
184        Self {
185            marketplace_name: marketplace_name.into(),
186            overrides: CliOverridesPatch::default(),
187        }
188    }
189
190    /// Replaces the default CLI overrides for this request.
191    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
192        self.overrides = overrides;
193        self
194    }
195}
196
197/// Request for `codex plugin marketplace upgrade [MARKETPLACE_NAME]`.
198#[derive(Clone, Debug, Eq, PartialEq)]
199pub struct PluginMarketplaceUpgradeRequest {
200    /// Optional configured marketplace name to upgrade.
201    pub marketplace_name: Option<String>,
202    /// Per-call CLI overrides layered on top of the builder.
203    pub overrides: CliOverridesPatch,
204}
205
206impl PluginMarketplaceUpgradeRequest {
207    pub fn new() -> Self {
208        Self {
209            marketplace_name: None,
210            overrides: CliOverridesPatch::default(),
211        }
212    }
213
214    /// Sets the optional marketplace name.
215    pub fn marketplace_name(mut self, marketplace_name: impl Into<String>) -> Self {
216        let marketplace_name = marketplace_name.into();
217        self.marketplace_name = (!marketplace_name.trim().is_empty()).then_some(marketplace_name);
218        self
219    }
220
221    /// Replaces the default CLI overrides for this request.
222    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
223        self.overrides = overrides;
224        self
225    }
226}
227
228impl Default for PluginMarketplaceUpgradeRequest {
229    fn default() -> Self {
230        Self::new()
231    }
232}