1#[must_use]
3pub fn new() -> Add<'static> {
4 Add::new()
5}
6
7#[derive(Debug)]
11pub struct Add<'a> {
12 base: crate::RepoBase<'a>,
13 all: bool,
14 pathspecs: Vec<&'a str>,
15}
16
17impl<'a> Add<'a> {
18 #[must_use]
19 fn new() -> Self {
20 Self {
21 base: crate::RepoBase::default(),
22 all: false,
23 pathspecs: Vec::new(),
24 }
25 }
26
27 crate::flag_methods! {
28 pub fn all / all_if, all, "Conditionally add all changes."
32 }
33
34 #[must_use]
36 pub fn pathspec(mut self, pathspec: &'a str) -> Self {
37 self.pathspecs.push(pathspec);
38 self
39 }
40
41 pub async fn status(self) -> Result<(), crate::Error> {
43 Ok(crate::Build::build(self)?.status().await?)
44 }
45}
46
47crate::impl_repo_base!(Add);
48
49impl Default for Add<'_> {
50 fn default() -> Self {
51 Self::new()
52 }
53}
54
55impl crate::Build for Add<'_> {
56 fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
57 Ok(self
58 .base
59 .command()?
60 .argument("add")
61 .optional_flag(self.all, "--all")
62 .arguments(self.pathspecs))
63 }
64}
65
66#[cfg(feature = "test-utils")]
67impl Add<'_> {
68 pub fn test_eq(&self, other: &cmd_proc::Command) {
70 let command = crate::Build::build(Self {
71 base: self.base,
72 all: self.all,
73 pathspecs: self.pathspecs.clone(),
74 })
75 .unwrap();
76 command.test_eq(other);
77 }
78}