use std::path::Path;
use crate::CommandError;
#[must_use]
pub fn new() -> Init<'static> {
Init::new()
}
#[derive(Debug)]
pub struct Init<'a> {
directory: Option<&'a Path>,
bare: bool,
}
impl<'a> Init<'a> {
#[must_use]
fn new() -> Self {
Self {
directory: None,
bare: false,
}
}
#[must_use]
pub fn directory(mut self, path: &'a Path) -> Self {
self.directory = Some(path);
self
}
crate::flag_methods! {
pub fn bare / bare_if, bare, "Conditionally create a bare repository."
}
pub async fn status(self) -> Result<(), CommandError> {
crate::Build::build(self).status().await
}
}
impl Default for Init<'_> {
fn default() -> Self {
Self::new()
}
}
impl crate::Build for Init<'_> {
fn build(self) -> cmd_proc::Command {
cmd_proc::Command::new("git")
.argument("init")
.optional_flag(self.bare, "--bare")
.optional_argument(self.directory)
}
}
#[cfg(feature = "test-utils")]
impl Init<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self {
directory: self.directory,
bare: self.bare,
});
command.test_eq(other);
}
}