use std::path::Path;
use crate::repository::Remote;
#[must_use]
pub fn new() -> LsRemote<'static> {
LsRemote::new()
}
#[derive(Debug)]
pub struct LsRemote<'a> {
repo_path: Option<&'a Path>,
heads: bool,
symref: bool,
remote: Option<&'a Remote>,
pattern: Option<&'a str>,
}
crate::impl_repo_path!(LsRemote);
impl<'a> LsRemote<'a> {
#[must_use]
fn new() -> Self {
Self {
repo_path: None,
heads: false,
symref: false,
remote: None,
pattern: None,
}
}
crate::flag_methods! {
pub fn heads / heads_if, heads, "Conditionally limit to refs/heads."
}
crate::flag_methods! {
pub fn symref / symref_if, symref, "Conditionally show underlying ref."
}
#[must_use]
pub fn remote(mut self, remote: &'a Remote) -> Self {
self.remote = Some(remote);
self
}
#[must_use]
pub fn pattern(mut self, pattern: &'a str) -> Self {
self.pattern = Some(pattern);
self
}
}
impl Default for LsRemote<'_> {
fn default() -> Self {
Self::new()
}
}
impl crate::Build for LsRemote<'_> {
fn build(self) -> cmd_proc::Command {
crate::base_command(self.repo_path)
.argument("ls-remote")
.optional_flag(self.heads, "--heads")
.optional_flag(self.symref, "--symref")
.optional_argument(self.remote)
.optional_argument(self.pattern)
}
}
#[cfg(feature = "test-utils")]
impl LsRemote<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self {
repo_path: self.repo_path,
heads: self.heads,
symref: self.symref,
remote: self.remote,
pattern: self.pattern,
});
command.test_eq(other);
}
}