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 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)]
|
||||||
@ -30,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;
|
||||||
|
|
||||||
@ -40,7 +47,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 +61,21 @@ 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 = 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,
|
||||||
|
};
|
||||||
|
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,10 +83,17 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
Ok(repos)
|
Ok(repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
let repo_paths = gather_repos(&start, 0)?;
|
let repos = gather_repos(&start, 0)?;
|
||||||
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!("Remotes: ");
|
||||||
|
for item in &repo.remotes {
|
||||||
|
print!("{item}");
|
||||||
|
print!(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
/*
|
/*
|
||||||
let indent = recurse_level * INDENT_INCREMENT;
|
let indent = recurse_level * INDENT_INCREMENT;
|
||||||
print!("{: <1$}", "", indent);
|
print!("{: <1$}", "", indent);
|
||||||
@ -74,7 +101,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