Compare commits
2 Commits
wip-repo-u
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
c7be05cfcc | ||
|
d63a1dc021 |
43
src/main.rs
43
src/main.rs
@ -4,12 +4,6 @@ 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)]
|
||||
@ -18,6 +12,11 @@ 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
|
||||
@ -36,7 +35,6 @@ fn main() -> Result<(), std::io::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
||||
use std::fs;
|
||||
|
||||
@ -62,15 +60,16 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
||||
.unwrap_or(false);
|
||||
|
||||
if let Ok(repository) = Repository::open(&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 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,
|
||||
@ -83,16 +82,16 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
||||
Ok(repos)
|
||||
}
|
||||
|
||||
let repos = gather_repos(&start, 0)?;
|
||||
let mut repos = gather_repos(&start, 0)?;
|
||||
repos.sort_unstable_by_key(|repo| repo.path.clone());
|
||||
for repo in &repos {
|
||||
let path = repo.path.strip_prefix(&start).unwrap();
|
||||
print!("Repository: {}", path.display().to_string().yellow());
|
||||
print!("Remotes: ");
|
||||
for item in &repo.remotes {
|
||||
print!("{item}");
|
||||
print!(" ");
|
||||
}
|
||||
|
||||
print!(" ");
|
||||
for (name, url) in &repo.remotes {
|
||||
print!("[{name} {url}]");
|
||||
}
|
||||
println!();
|
||||
/*
|
||||
let indent = recurse_level * INDENT_INCREMENT;
|
||||
|
Loading…
Reference in New Issue
Block a user