git_spawn/command/
show.rs1use crate::command::{CommandExecutor, CommandOutput, GitCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9pub struct ShowCommand {
10 pub executor: CommandExecutor,
12 pub objects: Vec<String>,
14 pub format: Option<String>,
16 pub stat: bool,
18 pub name_only: bool,
20 pub no_patch: bool,
22}
23
24impl ShowCommand {
25 #[must_use]
27 pub fn new() -> Self {
28 Self::default()
29 }
30
31 pub fn object(&mut self, o: impl Into<String>) -> &mut Self {
33 self.objects.push(o.into());
34 self
35 }
36
37 pub fn format(&mut self, fmt: impl Into<String>) -> &mut Self {
39 self.format = Some(fmt.into());
40 self
41 }
42
43 pub fn stat(&mut self) -> &mut Self {
45 self.stat = true;
46 self
47 }
48
49 pub fn name_only(&mut self) -> &mut Self {
51 self.name_only = true;
52 self
53 }
54
55 pub fn no_patch(&mut self) -> &mut Self {
57 self.no_patch = true;
58 self
59 }
60}
61
62#[async_trait]
63impl GitCommand for ShowCommand {
64 type Output = CommandOutput;
65 fn get_executor(&self) -> &CommandExecutor {
66 &self.executor
67 }
68 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
69 &mut self.executor
70 }
71 fn build_command_args(&self) -> Vec<String> {
72 let mut args = vec!["show".to_string()];
73 if let Some(f) = &self.format {
74 args.push(format!("--format={f}"));
75 }
76 if self.stat {
77 args.push("--stat".into());
78 }
79 if self.name_only {
80 args.push("--name-only".into());
81 }
82 if self.no_patch {
83 args.push("--no-patch".into());
84 }
85 args.extend(self.objects.iter().cloned());
86 args
87 }
88 async fn execute(&self) -> Result<CommandOutput> {
89 self.execute_raw().await
90 }
91}