Skip to content

Commit

Permalink
Merge pull request #56 from siketyan/feat/list-no-host
Browse files Browse the repository at this point in the history
feat: Support listing repos without host or owner
  • Loading branch information
siketyan authored Jan 16, 2023
2 parents 6df299b + a8d311c commit 0c3fb9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ 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<()> {
let root = Root::find()?;

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));

Expand Down
9 changes: 9 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 0c3fb9c

Please sign in to comment.