git-proc 0.6.0

Process-based git CLI wrapper with rich types
Documentation
/// Create a new `git add` command builder.
#[must_use]
pub fn new() -> Add<'static> {
    Add::new()
}

/// Builder for `git add` command.
///
/// See `git add --help` for full documentation.
#[derive(Debug)]
pub struct Add<'a> {
    base: crate::RepoBase<'a>,
    all: bool,
    pathspecs: Vec<&'a str>,
}

impl<'a> Add<'a> {
    #[must_use]
    fn new() -> Self {
        Self {
            base: crate::RepoBase::default(),
            all: false,
            pathspecs: Vec::new(),
        }
    }

    crate::flag_methods! {
        /// Add all changes (new, modified, deleted).
        ///
        /// Corresponds to `--all` or `-A`.
        pub fn all / all_if, all, "Conditionally add all changes."
    }

    /// Add a pathspec to stage.
    #[must_use]
    pub fn pathspec(mut self, pathspec: &'a str) -> Self {
        self.pathspecs.push(pathspec);
        self
    }

    /// Execute the command and return the exit status.
    pub async fn status(self) -> Result<(), crate::Error> {
        Ok(crate::Build::build(self)?.status().await?)
    }
}

crate::impl_repo_base!(Add);

impl Default for Add<'_> {
    fn default() -> Self {
        Self::new()
    }
}

impl crate::Build for Add<'_> {
    fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
        Ok(self
            .base
            .command()?
            .argument("add")
            .optional_flag(self.all, "--all")
            .arguments(self.pathspecs))
    }
}

#[cfg(feature = "test-utils")]
impl Add<'_> {
    /// Compare the built command with another command using debug representation.
    pub fn test_eq(&self, other: &cmd_proc::Command) {
        let command = crate::Build::build(Self {
            base: self.base,
            all: self.all,
            pathspecs: self.pathspecs.clone(),
        })
        .unwrap();
        command.test_eq(other);
    }
}