Skip to main content

claude_code/commands/
plugin.rs

1use std::{path::PathBuf, time::Duration};
2
3use super::command::ClaudeCommandRequest;
4
5#[derive(Debug, Clone)]
6pub struct PluginRequest {
7    pub(crate) timeout: Option<Duration>,
8}
9
10impl PluginRequest {
11    pub fn new() -> Self {
12        Self { timeout: None }
13    }
14
15    pub fn timeout(mut self, timeout: Duration) -> Self {
16        self.timeout = Some(timeout);
17        self
18    }
19
20    pub fn into_command(self) -> ClaudeCommandRequest {
21        let mut cmd = ClaudeCommandRequest::new(["plugin"]);
22        if let Some(timeout) = self.timeout {
23            cmd = cmd.timeout(timeout);
24        }
25        cmd
26    }
27}
28
29impl Default for PluginRequest {
30    fn default() -> Self {
31        Self::new()
32    }
33}
34
35#[derive(Debug, Clone)]
36pub struct PluginMarketplaceRequest {
37    pub(crate) timeout: Option<Duration>,
38}
39
40impl PluginMarketplaceRequest {
41    pub fn new() -> Self {
42        Self { timeout: None }
43    }
44
45    pub fn timeout(mut self, timeout: Duration) -> Self {
46        self.timeout = Some(timeout);
47        self
48    }
49
50    pub fn into_command(self) -> ClaudeCommandRequest {
51        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace"]);
52        if let Some(timeout) = self.timeout {
53            cmd = cmd.timeout(timeout);
54        }
55        cmd
56    }
57}
58
59impl Default for PluginMarketplaceRequest {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65#[derive(Debug, Clone)]
66pub struct PluginDisableRequest {
67    pub(crate) all: bool,
68    pub(crate) scope: Option<String>,
69    pub(crate) timeout: Option<Duration>,
70}
71
72impl PluginDisableRequest {
73    pub fn new() -> Self {
74        Self {
75            all: false,
76            scope: None,
77            timeout: None,
78        }
79    }
80
81    pub fn all(mut self, all: bool) -> Self {
82        self.all = all;
83        self
84    }
85
86    pub fn scope(mut self, scope: impl Into<String>) -> Self {
87        self.scope = Some(scope.into());
88        self
89    }
90
91    pub fn timeout(mut self, timeout: Duration) -> Self {
92        self.timeout = Some(timeout);
93        self
94    }
95
96    pub fn into_command(self) -> ClaudeCommandRequest {
97        let mut args = Vec::<String>::new();
98        if self.all {
99            args.push("--all".to_string());
100        }
101        if let Some(scope) = self.scope {
102            args.push("--scope".to_string());
103            args.push(scope);
104        }
105
106        let mut cmd = ClaudeCommandRequest::new(["plugin", "disable"]).args(args);
107        if let Some(timeout) = self.timeout {
108            cmd = cmd.timeout(timeout);
109        }
110        cmd
111    }
112}
113
114impl Default for PluginDisableRequest {
115    fn default() -> Self {
116        Self::new()
117    }
118}
119
120#[derive(Debug, Clone)]
121pub struct PluginEnableRequest {
122    pub(crate) plugin: String,
123    pub(crate) scope: Option<String>,
124    pub(crate) timeout: Option<Duration>,
125}
126
127impl PluginEnableRequest {
128    pub fn new(plugin: impl Into<String>) -> Self {
129        Self {
130            plugin: plugin.into(),
131            scope: None,
132            timeout: None,
133        }
134    }
135
136    pub fn scope(mut self, scope: impl Into<String>) -> Self {
137        self.scope = Some(scope.into());
138        self
139    }
140
141    pub fn timeout(mut self, timeout: Duration) -> Self {
142        self.timeout = Some(timeout);
143        self
144    }
145
146    pub fn into_command(self) -> ClaudeCommandRequest {
147        let mut args = Vec::<String>::new();
148        if let Some(scope) = self.scope {
149            args.push("--scope".to_string());
150            args.push(scope);
151        }
152        args.push(self.plugin);
153
154        let mut cmd = ClaudeCommandRequest::new(["plugin", "enable"]).args(args);
155        if let Some(timeout) = self.timeout {
156            cmd = cmd.timeout(timeout);
157        }
158        cmd
159    }
160}
161
162#[derive(Debug, Clone)]
163pub struct PluginInstallRequest {
164    pub(crate) scope: Option<String>,
165    pub(crate) timeout: Option<Duration>,
166}
167
168impl PluginInstallRequest {
169    pub fn new() -> Self {
170        Self {
171            scope: None,
172            timeout: None,
173        }
174    }
175
176    pub fn scope(mut self, scope: impl Into<String>) -> Self {
177        self.scope = Some(scope.into());
178        self
179    }
180
181    pub fn timeout(mut self, timeout: Duration) -> Self {
182        self.timeout = Some(timeout);
183        self
184    }
185
186    pub fn into_command(self) -> ClaudeCommandRequest {
187        let mut args = Vec::<String>::new();
188        if let Some(scope) = self.scope {
189            args.push("--scope".to_string());
190            args.push(scope);
191        }
192
193        let mut cmd = ClaudeCommandRequest::new(["plugin", "install"]).args(args);
194        if let Some(timeout) = self.timeout {
195            cmd = cmd.timeout(timeout);
196        }
197        cmd
198    }
199}
200
201impl Default for PluginInstallRequest {
202    fn default() -> Self {
203        Self::new()
204    }
205}
206
207#[derive(Debug, Clone)]
208pub struct PluginUninstallRequest {
209    pub(crate) scope: Option<String>,
210    pub(crate) timeout: Option<Duration>,
211}
212
213impl PluginUninstallRequest {
214    pub fn new() -> Self {
215        Self {
216            scope: None,
217            timeout: None,
218        }
219    }
220
221    pub fn scope(mut self, scope: impl Into<String>) -> Self {
222        self.scope = Some(scope.into());
223        self
224    }
225
226    pub fn timeout(mut self, timeout: Duration) -> Self {
227        self.timeout = Some(timeout);
228        self
229    }
230
231    pub fn into_command(self) -> ClaudeCommandRequest {
232        let mut args = Vec::<String>::new();
233        if let Some(scope) = self.scope {
234            args.push("--scope".to_string());
235            args.push(scope);
236        }
237
238        let mut cmd = ClaudeCommandRequest::new(["plugin", "uninstall"]).args(args);
239        if let Some(timeout) = self.timeout {
240            cmd = cmd.timeout(timeout);
241        }
242        cmd
243    }
244}
245
246impl Default for PluginUninstallRequest {
247    fn default() -> Self {
248        Self::new()
249    }
250}
251
252#[derive(Debug, Clone)]
253pub struct PluginUpdateRequest {
254    pub(crate) plugin: String,
255    pub(crate) scope: Option<String>,
256    pub(crate) timeout: Option<Duration>,
257}
258
259impl PluginUpdateRequest {
260    pub fn new(plugin: impl Into<String>) -> Self {
261        Self {
262            plugin: plugin.into(),
263            scope: None,
264            timeout: None,
265        }
266    }
267
268    pub fn scope(mut self, scope: impl Into<String>) -> Self {
269        self.scope = Some(scope.into());
270        self
271    }
272
273    pub fn timeout(mut self, timeout: Duration) -> Self {
274        self.timeout = Some(timeout);
275        self
276    }
277
278    pub fn into_command(self) -> ClaudeCommandRequest {
279        let mut args = Vec::<String>::new();
280        if let Some(scope) = self.scope {
281            args.push("--scope".to_string());
282            args.push(scope);
283        }
284        args.push(self.plugin);
285
286        let mut cmd = ClaudeCommandRequest::new(["plugin", "update"]).args(args);
287        if let Some(timeout) = self.timeout {
288            cmd = cmd.timeout(timeout);
289        }
290        cmd
291    }
292}
293
294#[derive(Debug, Clone)]
295pub struct PluginValidateRequest {
296    pub(crate) path: PathBuf,
297    pub(crate) timeout: Option<Duration>,
298}
299
300impl PluginValidateRequest {
301    pub fn new(path: impl Into<PathBuf>) -> Self {
302        Self {
303            path: path.into(),
304            timeout: None,
305        }
306    }
307
308    pub fn timeout(mut self, timeout: Duration) -> Self {
309        self.timeout = Some(timeout);
310        self
311    }
312
313    pub fn into_command(self) -> ClaudeCommandRequest {
314        let mut cmd = ClaudeCommandRequest::new(["plugin", "validate"])
315            .arg(self.path.to_string_lossy().to_string());
316        if let Some(timeout) = self.timeout {
317            cmd = cmd.timeout(timeout);
318        }
319        cmd
320    }
321}
322
323#[derive(Debug, Clone)]
324pub struct PluginListRequest {
325    pub(crate) available: bool,
326    pub(crate) json: bool,
327    pub(crate) timeout: Option<Duration>,
328}
329
330impl PluginListRequest {
331    pub fn new() -> Self {
332        Self {
333            available: false,
334            json: false,
335            timeout: None,
336        }
337    }
338
339    pub fn available(mut self, available: bool) -> Self {
340        self.available = available;
341        self
342    }
343
344    pub fn json(mut self, json: bool) -> Self {
345        self.json = json;
346        self
347    }
348
349    pub fn timeout(mut self, timeout: Duration) -> Self {
350        self.timeout = Some(timeout);
351        self
352    }
353
354    pub fn into_command(self) -> ClaudeCommandRequest {
355        let mut args = Vec::<String>::new();
356        if self.available {
357            args.push("--available".to_string());
358        }
359        if self.json {
360            args.push("--json".to_string());
361        }
362
363        let mut cmd = ClaudeCommandRequest::new(["plugin", "list"]).args(args);
364        if let Some(timeout) = self.timeout {
365            cmd = cmd.timeout(timeout);
366        }
367        cmd
368    }
369}
370
371impl Default for PluginListRequest {
372    fn default() -> Self {
373        Self::new()
374    }
375}
376
377#[derive(Debug, Clone)]
378pub struct PluginManifestRequest {
379    pub(crate) timeout: Option<Duration>,
380}
381
382impl PluginManifestRequest {
383    pub fn new() -> Self {
384        Self { timeout: None }
385    }
386
387    pub fn timeout(mut self, timeout: Duration) -> Self {
388        self.timeout = Some(timeout);
389        self
390    }
391
392    pub fn into_command(self) -> ClaudeCommandRequest {
393        let mut cmd = ClaudeCommandRequest::new(["plugin", "manifest"]);
394        if let Some(timeout) = self.timeout {
395            cmd = cmd.timeout(timeout);
396        }
397        cmd
398    }
399}
400
401impl Default for PluginManifestRequest {
402    fn default() -> Self {
403        Self::new()
404    }
405}
406
407#[derive(Debug, Clone)]
408pub struct PluginManifestMarketplaceRequest {
409    pub(crate) timeout: Option<Duration>,
410}
411
412impl PluginManifestMarketplaceRequest {
413    pub fn new() -> Self {
414        Self { timeout: None }
415    }
416
417    pub fn timeout(mut self, timeout: Duration) -> Self {
418        self.timeout = Some(timeout);
419        self
420    }
421
422    pub fn into_command(self) -> ClaudeCommandRequest {
423        let mut cmd = ClaudeCommandRequest::new(["plugin", "manifest", "marketplace"]);
424        if let Some(timeout) = self.timeout {
425            cmd = cmd.timeout(timeout);
426        }
427        cmd
428    }
429}
430
431impl Default for PluginManifestMarketplaceRequest {
432    fn default() -> Self {
433        Self::new()
434    }
435}
436
437#[derive(Debug, Clone)]
438pub struct PluginMarketplaceRepoRequest {
439    pub(crate) timeout: Option<Duration>,
440}
441
442impl PluginMarketplaceRepoRequest {
443    pub fn new() -> Self {
444        Self { timeout: None }
445    }
446
447    pub fn timeout(mut self, timeout: Duration) -> Self {
448        self.timeout = Some(timeout);
449        self
450    }
451
452    pub fn into_command(self) -> ClaudeCommandRequest {
453        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace", "repo"]);
454        if let Some(timeout) = self.timeout {
455            cmd = cmd.timeout(timeout);
456        }
457        cmd
458    }
459}
460
461impl Default for PluginMarketplaceRepoRequest {
462    fn default() -> Self {
463        Self::new()
464    }
465}
466
467#[derive(Debug, Clone)]
468pub struct PluginMarketplaceAddRequest {
469    pub(crate) source: String,
470    pub(crate) timeout: Option<Duration>,
471}
472
473impl PluginMarketplaceAddRequest {
474    pub fn new(source: impl Into<String>) -> Self {
475        Self {
476            source: source.into(),
477            timeout: None,
478        }
479    }
480
481    pub fn timeout(mut self, timeout: Duration) -> Self {
482        self.timeout = Some(timeout);
483        self
484    }
485
486    pub fn into_command(self) -> ClaudeCommandRequest {
487        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace", "add"]).arg(self.source);
488        if let Some(timeout) = self.timeout {
489            cmd = cmd.timeout(timeout);
490        }
491        cmd
492    }
493}
494
495#[derive(Debug, Clone)]
496pub struct PluginMarketplaceListRequest {
497    pub(crate) json: bool,
498    pub(crate) timeout: Option<Duration>,
499}
500
501impl PluginMarketplaceListRequest {
502    pub fn new() -> Self {
503        Self {
504            json: false,
505            timeout: None,
506        }
507    }
508
509    pub fn json(mut self, json: bool) -> Self {
510        self.json = json;
511        self
512    }
513
514    pub fn timeout(mut self, timeout: Duration) -> Self {
515        self.timeout = Some(timeout);
516        self
517    }
518
519    pub fn into_command(self) -> ClaudeCommandRequest {
520        let mut args = Vec::<String>::new();
521        if self.json {
522            args.push("--json".to_string());
523        }
524
525        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace", "list"]).args(args);
526        if let Some(timeout) = self.timeout {
527            cmd = cmd.timeout(timeout);
528        }
529        cmd
530    }
531}
532
533impl Default for PluginMarketplaceListRequest {
534    fn default() -> Self {
535        Self::new()
536    }
537}
538
539#[derive(Debug, Clone)]
540pub struct PluginMarketplaceRemoveRequest {
541    pub(crate) timeout: Option<Duration>,
542}
543
544impl PluginMarketplaceRemoveRequest {
545    pub fn new() -> Self {
546        Self { timeout: None }
547    }
548
549    pub fn timeout(mut self, timeout: Duration) -> Self {
550        self.timeout = Some(timeout);
551        self
552    }
553
554    pub fn into_command(self) -> ClaudeCommandRequest {
555        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace", "remove"]);
556        if let Some(timeout) = self.timeout {
557            cmd = cmd.timeout(timeout);
558        }
559        cmd
560    }
561}
562
563impl Default for PluginMarketplaceRemoveRequest {
564    fn default() -> Self {
565        Self::new()
566    }
567}
568
569#[derive(Debug, Clone)]
570pub struct PluginMarketplaceUpdateRequest {
571    pub(crate) timeout: Option<Duration>,
572}
573
574impl PluginMarketplaceUpdateRequest {
575    pub fn new() -> Self {
576        Self { timeout: None }
577    }
578
579    pub fn timeout(mut self, timeout: Duration) -> Self {
580        self.timeout = Some(timeout);
581        self
582    }
583
584    pub fn into_command(self) -> ClaudeCommandRequest {
585        let mut cmd = ClaudeCommandRequest::new(["plugin", "marketplace", "update"]);
586        if let Some(timeout) = self.timeout {
587            cmd = cmd.timeout(timeout);
588        }
589        cmd
590    }
591}
592
593impl Default for PluginMarketplaceUpdateRequest {
594    fn default() -> Self {
595        Self::new()
596    }
597}