1use std::path::Path;
2
3#[must_use]
5pub fn new() -> ShowRef<'static> {
6 ShowRef::new()
7}
8
9#[derive(Debug)]
13pub struct ShowRef<'a> {
14 repo_path: Option<&'a Path>,
15 verify: bool,
16 pattern: Option<&'a str>,
17}
18
19impl<'a> ShowRef<'a> {
20 #[must_use]
21 fn new() -> Self {
22 Self {
23 repo_path: None,
24 verify: false,
25 pattern: None,
26 }
27 }
28
29 #[must_use]
31 pub fn repo_path(mut self, path: &'a Path) -> Self {
32 self.repo_path = Some(path);
33 self
34 }
35
36 crate::flag_methods! {
37 pub fn verify / verify_if, verify, "Conditionally enable strict reference checking."
41 }
42
43 #[must_use]
45 pub fn pattern(mut self, pattern: &'a str) -> Self {
46 self.pattern = Some(pattern);
47 self
48 }
49
50 #[must_use]
54 pub fn stdout(self) -> cmd_proc::Capture {
55 self.build().stdout()
56 }
57
58 fn build(self) -> cmd_proc::Command {
59 crate::base_command(self.repo_path)
60 .argument("show-ref")
61 .optional_argument(self.verify.then_some("--verify"))
62 .optional_argument(self.pattern)
63 }
64}
65
66impl Default for ShowRef<'_> {
67 fn default() -> Self {
68 Self::new()
69 }
70}
71
72#[cfg(feature = "test-utils")]
73impl ShowRef<'_> {
74 pub fn test_eq(&self, other: &cmd_proc::Command) {
76 let command = Self {
77 repo_path: self.repo_path,
78 verify: self.verify,
79 pattern: self.pattern,
80 }
81 .build();
82 command.test_eq(other);
83 }
84}