Compare commits

..

1 Commits

Author SHA1 Message Date
Greg Shuflin
1fcdc6305a WIP display repo urls 2024-10-24 16:57:06 -07:00

View File

@ -4,6 +4,12 @@ use clap::{Parser, Subcommand};
use colored::*;
use git2::Repository;
#[derive(Debug)]
struct Repo {
path: PathBuf,
remotes: Vec<(String, String)>
}
/// Repotool is a tool to manage multiple code repositories
#[derive(Parser, Debug)]
#[command(version, about)]
@ -12,11 +18,6 @@ struct Args {
command: Command,
}
struct Repo {
path: PathBuf,
remotes: Vec<(String, String)>
}
#[derive(Subcommand, Debug)]
enum Command {
///List all repositories found in the directory tree
@ -35,6 +36,7 @@ fn main() -> Result<(), std::io::Error> {
Ok(())
}
fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
use std::fs;
@ -60,16 +62,15 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
.unwrap_or(false);
if let Ok(repository) = Repository::open(&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 remotes = match repository.remotes() {
Ok(remotes) => {
remotes.into_iter().map(|s| s.map(|s| s.to_string()).unwrap_or("".to_string())).collect()
},
Err(err) => {
eprintln!("Error: {err}");
vec![]
},
};
let repo = Repo {
path,
remotes,
@ -82,16 +83,16 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
Ok(repos)
}
let mut repos = gather_repos(&start, 0)?;
repos.sort_unstable_by_key(|repo| repo.path.clone());
let repos = gather_repos(&start, 0)?;
for repo in &repos {
let path = repo.path.strip_prefix(&start).unwrap();
print!("Repository: {}", path.display().to_string().yellow());
print!(" ");
for (name, url) in &repo.remotes {
print!("[{name} {url}]");
print!("Remotes: ");
for item in &repo.remotes {
print!("{item}");
print!(" ");
}
println!();
/*
let indent = recurse_level * INDENT_INCREMENT;