1use std::path::Path;
2
3use crate::CommandError;
4
5#[must_use]
7pub fn new(key: &str) -> Config<'_> {
8 Config::new(key)
9}
10
11#[derive(Debug)]
15pub struct Config<'a> {
16 repo_path: Option<&'a Path>,
17 key: &'a str,
18 value: Option<&'a str>,
19}
20
21crate::impl_repo_path!(Config);
22
23impl<'a> Config<'a> {
24 #[must_use]
25 fn new(key: &'a str) -> Self {
26 Self {
27 repo_path: None,
28 key,
29 value: None,
30 }
31 }
32
33 #[must_use]
35 pub fn value(mut self, value: &'a str) -> Self {
36 self.value = Some(value);
37 self
38 }
39
40 pub async fn status(self) -> Result<(), CommandError> {
42 crate::Build::build(self).status().await
43 }
44}
45
46impl crate::Build for Config<'_> {
47 fn build(self) -> cmd_proc::Command {
48 crate::base_command(self.repo_path)
49 .argument("config")
50 .argument(self.key)
51 .optional_argument(self.value)
52 }
53}
54
55#[cfg(feature = "test-utils")]
56impl Config<'_> {
57 pub fn test_eq(&self, other: &cmd_proc::Command) {
59 let command = crate::Build::build(Self {
60 repo_path: self.repo_path,
61 key: self.key,
62 value: self.value,
63 });
64 command.test_eq(other);
65 }
66}