use std::path::Path;
use crate::CommandError;
#[must_use]
pub fn new(key: &str) -> Config<'_> {
Config::new(key)
}
#[derive(Debug)]
pub struct Config<'a> {
repo_path: Option<&'a Path>,
key: &'a str,
value: Option<&'a str>,
}
crate::impl_repo_path!(Config);
impl<'a> Config<'a> {
#[must_use]
fn new(key: &'a str) -> Self {
Self {
repo_path: None,
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<(), CommandError> {
crate::Build::build(self).status().await
}
}
impl crate::Build for Config<'_> {
fn build(self) -> cmd_proc::Command {
crate::base_command(self.repo_path)
.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 {
repo_path: self.repo_path,
key: self.key,
value: self.value,
});
command.test_eq(other);
}
}