1use crate::command::{CommandExecutor, CommandOutput, GitCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9pub struct RmCommand {
10 pub executor: CommandExecutor,
12 pub paths: Vec<String>,
14 pub cached: bool,
16 pub recursive: bool,
18 pub force: bool,
20 pub dry_run: bool,
22 pub quiet: bool,
24}
25
26impl RmCommand {
27 #[must_use]
29 pub fn new() -> Self {
30 Self::default()
31 }
32 pub fn path(&mut self, p: impl Into<String>) -> &mut Self {
34 self.paths.push(p.into());
35 self
36 }
37 pub fn cached(&mut self) -> &mut Self {
39 self.cached = true;
40 self
41 }
42 pub fn recursive(&mut self) -> &mut Self {
44 self.recursive = true;
45 self
46 }
47 pub fn force(&mut self) -> &mut Self {
49 self.force = true;
50 self
51 }
52 pub fn dry_run(&mut self) -> &mut Self {
54 self.dry_run = true;
55 self
56 }
57 pub fn quiet(&mut self) -> &mut Self {
59 self.quiet = true;
60 self
61 }
62}
63
64#[async_trait]
65impl GitCommand for RmCommand {
66 type Output = CommandOutput;
67 fn get_executor(&self) -> &CommandExecutor {
68 &self.executor
69 }
70 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
71 &mut self.executor
72 }
73 fn build_command_args(&self) -> Vec<String> {
74 let mut args = vec!["rm".to_string()];
75 if self.cached {
76 args.push("--cached".into());
77 }
78 if self.recursive {
79 args.push("-r".into());
80 }
81 if self.force {
82 args.push("--force".into());
83 }
84 if self.dry_run {
85 args.push("--dry-run".into());
86 }
87 if self.quiet {
88 args.push("--quiet".into());
89 }
90 if !self.paths.is_empty() {
91 args.push("--".into());
92 args.extend(self.paths.iter().cloned());
93 }
94 args
95 }
96 async fn execute(&self) -> Result<CommandOutput> {
97 self.execute_raw().await
98 }
99}