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