1use std::path::Path;
2
3use crate::CommandError;
4
5#[must_use]
7pub fn new() -> Add<'static> {
8 Add::new()
9}
10
11#[derive(Debug)]
15pub struct Add<'a> {
16 repo_path: Option<&'a Path>,
17 all: bool,
18 pathspecs: Vec<&'a str>,
19}
20
21impl<'a> Add<'a> {
22 #[must_use]
23 fn new() -> Self {
24 Self {
25 repo_path: None,
26 all: false,
27 pathspecs: Vec::new(),
28 }
29 }
30
31 crate::flag_methods! {
32 pub fn all / all_if, all, "Conditionally add all changes."
36 }
37
38 #[must_use]
40 pub fn pathspec(mut self, pathspec: &'a str) -> Self {
41 self.pathspecs.push(pathspec);
42 self
43 }
44
45 pub async fn status(self) -> Result<(), CommandError> {
47 crate::Build::build(self).status().await
48 }
49}
50
51crate::impl_repo_path!(Add);
52
53impl Default for Add<'_> {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59impl crate::Build for Add<'_> {
60 fn build(self) -> cmd_proc::Command {
61 crate::base_command(self.repo_path)
62 .argument("add")
63 .optional_flag(self.all, "--all")
64 .arguments(self.pathspecs)
65 }
66}
67
68#[cfg(feature = "test-utils")]
69impl Add<'_> {
70 pub fn test_eq(&self, other: &cmd_proc::Command) {
72 let command = crate::Build::build(Self {
73 repo_path: self.repo_path,
74 all: self.all,
75 pathspecs: self.pathspecs.clone(),
76 });
77 command.test_eq(other);
78 }
79}