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 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)]
|
||||||
@ -18,6 +12,11 @@ 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
|
||||||
@ -36,7 +35,6 @@ 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;
|
||||||
|
|
||||||
@ -62,15 +60,16 @@ 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 = match repository.remotes() {
|
let remotes_array = repository.remotes().unwrap();
|
||||||
Ok(remotes) => {
|
|
||||||
remotes.into_iter().map(|s| s.map(|s| s.to_string()).unwrap_or("".to_string())).collect()
|
let remotes = remotes_array.into_iter().map(|remote_name| {
|
||||||
},
|
let name = remote_name.unwrap();
|
||||||
Err(err) => {
|
let remote = repository.find_remote(name).unwrap();
|
||||||
eprintln!("Error: {err}");
|
let url = remote.url().unwrap();
|
||||||
vec![]
|
|
||||||
},
|
(name.to_string(), url.to_string())
|
||||||
};
|
}).collect();
|
||||||
|
|
||||||
let repo = Repo {
|
let repo = Repo {
|
||||||
path,
|
path,
|
||||||
remotes,
|
remotes,
|
||||||
@ -83,16 +82,16 @@ fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
|||||||
Ok(repos)
|
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 {
|
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: ");
|
|
||||||
for item in &repo.remotes {
|
|
||||||
print!("{item}");
|
|
||||||
print!(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
print!(" ");
|
||||||
|
for (name, url) in &repo.remotes {
|
||||||
|
print!("[{name} {url}]");
|
||||||
|
}
|
||||||
println!();
|
println!();
|
||||||
/*
|
/*
|
||||||
let indent = recurse_level * INDENT_INCREMENT;
|
let indent = recurse_level * INDENT_INCREMENT;
|
||||||
|
Loading…
Reference in New Issue
Block a user