diff --git a/src/cmd/list.rs b/src/cmd/list.rs index 3a468a0..5ca028f 100644 --- a/src/cmd/list.rs +++ b/src/cmd/list.rs @@ -6,7 +6,15 @@ use crate::repository::Repositories; use crate::root::Root; #[derive(Debug, Parser)] -pub struct Cmd {} +pub struct Cmd { + /// Lists repositories without their hosts. + #[clap(long)] + no_host: bool, + + /// Lists repositories without their owners. + #[clap(long)] + no_owner: bool, +} impl Cmd { pub fn run(self) -> Result<()> { @@ -14,7 +22,7 @@ impl Cmd { Repositories::try_collect(&root)? .into_iter() - .map(|(path, _)| path.to_string()) + .map(|(path, _)| path.to_string_with(!self.no_host, !self.no_owner)) .sorted() .for_each(|path| println!("{}", path)); diff --git a/src/path.rs b/src/path.rs index a781fa0..f094f7a 100644 --- a/src/path.rs +++ b/src/path.rs @@ -34,6 +34,15 @@ impl<'a> Path<'a> { repo: url.repo.clone(), } } + + pub fn to_string_with(&self, host: bool, owner: bool) -> String { + match (host, owner) { + (false, true) => format!("{}/{}", self.owner, self.repo), + (true, false) => format!("{}:{}", self.host, self.repo), + (false, false) => format!("{}", self.repo), + _ => format!("{}:{}/{}", self.host, self.owner, self.repo), + } + } } impl<'a> Display for Path<'a> {