#[must_use]
pub fn new(key: &str) -> Config<'_> {
Config::new(key)
}
#[must_use]
pub fn list() -> List<'static> {
List::new()
}
#[derive(Debug)]
pub struct Config<'a> {
base: crate::RepoBase<'a>,
key: &'a str,
value: Option<&'a str>,
}
crate::impl_repo_base!(Config);
impl<'a> Config<'a> {
#[must_use]
fn new(key: &'a str) -> Self {
Self {
base: crate::RepoBase::default(),
key,
value: None,
}
}
#[must_use]
pub fn value(mut self, value: &'a str) -> Self {
self.value = Some(value);
self
}
pub async fn status(self) -> Result<(), crate::Error> {
Ok(crate::Build::build(self)?.status().await?)
}
}
impl crate::Build for Config<'_> {
fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
Ok(self
.base
.command()?
.argument("config")
.argument(self.key)
.optional_argument(self.value))
}
}
#[cfg(feature = "test-utils")]
impl Config<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self {
base: self.base,
key: self.key,
value: self.value,
})
.unwrap();
command.test_eq(other);
}
}
#[derive(Debug)]
pub struct List<'a> {
base: crate::RepoBase<'a>,
}
crate::impl_repo_base!(List);
impl<'a> List<'a> {
#[must_use]
fn new() -> Self {
Self {
base: crate::RepoBase::default(),
}
}
}
impl Default for List<'_> {
fn default() -> Self {
Self::new()
}
}
impl crate::Build for List<'_> {
fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
Ok(self.base.command()?.argument("config").argument("--list"))
}
}
#[cfg(feature = "test-utils")]
impl List<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self { base: self.base }).unwrap();
command.test_eq(other);
}
}
#[cfg(all(test, feature = "test-utils"))]
mod tests {
use super::*;
#[test]
fn test_config_list_command() {
let expected = cmd_proc::Command::new("git")
.argument("config")
.argument("--list");
list().test_eq(&expected);
}
}