use std::path::Path;
use crate::CommandError;
#[must_use]
pub fn new() -> Add<'static> {
Add::new()
}
#[derive(Debug)]
pub struct Add<'a> {
repo_path: Option<&'a Path>,
all: bool,
pathspecs: Vec<&'a str>,
}
impl<'a> Add<'a> {
#[must_use]
fn new() -> Self {
Self {
repo_path: None,
all: false,
pathspecs: Vec::new(),
}
}
crate::flag_methods! {
pub fn all / all_if, all, "Conditionally add all changes."
}
#[must_use]
pub fn pathspec(mut self, pathspec: &'a str) -> Self {
self.pathspecs.push(pathspec);
self
}
pub async fn status(self) -> Result<(), CommandError> {
crate::Build::build(self).status().await
}
}
crate::impl_repo_path!(Add);
impl Default for Add<'_> {
fn default() -> Self {
Self::new()
}
}
impl crate::Build for Add<'_> {
fn build(self) -> cmd_proc::Command {
crate::base_command(self.repo_path)
.argument("add")
.optional_flag(self.all, "--all")
.arguments(self.pathspecs)
}
}
#[cfg(feature = "test-utils")]
impl Add<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self {
repo_path: self.repo_path,
all: self.all,
pathspecs: self.pathspecs.clone(),
});
command.test_eq(other);
}
}