Compare commits
1 Commits
master
...
wip-repo-u
Author | SHA1 | Date | |
---|---|---|---|
|
1fcdc6305a |
43
src/main.rs
43
src/main.rs
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user