Get origins
This commit is contained in:
parent
d63a1dc021
commit
c7be05cfcc
43
src/main.rs
43
src/main.rs
@ -12,6 +12,11 @@ struct Args {
|
|||||||
command: Command,
|
command: Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Repo {
|
||||||
|
path: PathBuf,
|
||||||
|
remotes: Vec<(String, String)>
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
///List all repositories found in the directory tree
|
///List all repositories found in the directory tree
|
||||||
@ -40,7 +45,7 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
);
|
);
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
fn gather_repos(dir: &Path, recurse_level: usize) -> Result<Vec<PathBuf>, std::io::Error> {
|
fn gather_repos(dir: &Path, recurse_level: usize) -> Result<Vec<Repo>, std::io::Error> {
|
||||||
let mut repos = Vec::new();
|
let mut repos = Vec::new();
|
||||||
|
|
||||||
let dir = fs::read_dir(dir)?;
|
let dir = fs::read_dir(dir)?;
|
||||||
@ -54,8 +59,22 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
.map(|byte| *byte == b'.')
|
.map(|byte| *byte == b'.')
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if let Ok(_repo) = Repository::open(&path) {
|
if let Ok(repository) = Repository::open(&path) {
|
||||||
repos.push(path);
|
let remotes_array = repository.remotes().unwrap();
|
||||||
|
|
||||||
|
let remotes = remotes_array.into_iter().map(|remote_name| {
|
||||||
|
let name = remote_name.unwrap();
|
||||||
|
let remote = repository.find_remote(name).unwrap();
|
||||||
|
let url = remote.url().unwrap();
|
||||||
|
|
||||||
|
(name.to_string(), url.to_string())
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
let repo = Repo {
|
||||||
|
path,
|
||||||
|
remotes,
|
||||||
|
};
|
||||||
|
repos.push(repo);
|
||||||
} else if path.is_dir() && !hidden {
|
} else if path.is_dir() && !hidden {
|
||||||
repos.extend(gather_repos(&path, recurse_level + 1)?.into_iter());
|
repos.extend(gather_repos(&path, recurse_level + 1)?.into_iter());
|
||||||
}
|
}
|
||||||
@ -63,11 +82,17 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
Ok(repos)
|
Ok(repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut repo_paths = gather_repos(&start, 0)?;
|
let mut repos = gather_repos(&start, 0)?;
|
||||||
repo_paths.sort();
|
repos.sort_unstable_by_key(|repo| repo.path.clone());
|
||||||
for path in &repo_paths {
|
for repo in &repos {
|
||||||
let path = path.strip_prefix(&start).unwrap();
|
let path = repo.path.strip_prefix(&start).unwrap();
|
||||||
println!("Repository: {}", path.display().to_string().yellow());
|
print!("Repository: {}", path.display().to_string().yellow());
|
||||||
|
|
||||||
|
print!(" ");
|
||||||
|
for (name, url) in &repo.remotes {
|
||||||
|
print!("[{name} {url}]");
|
||||||
|
}
|
||||||
|
println!();
|
||||||
/*
|
/*
|
||||||
let indent = recurse_level * INDENT_INCREMENT;
|
let indent = recurse_level * INDENT_INCREMENT;
|
||||||
print!("{: <1$}", "", indent);
|
print!("{: <1$}", "", indent);
|
||||||
@ -75,7 +100,7 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
println!("Total repos: {}", repo_paths.len());
|
println!("Total repos: {}", repos.len());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user