Work
This commit is contained in:
parent
e731429523
commit
0691736546
50
src/main.rs
50
src/main.rs
@ -1,7 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use colored::*;
|
||||
use clap::{Parser, Subcommand};
|
||||
use colored::*;
|
||||
use git2::Repository;
|
||||
|
||||
/// Repotool is a tool to manage multiple code repositories
|
||||
#[derive(Parser, Debug)]
|
||||
@ -30,8 +31,49 @@ fn main() -> Result<(), std::io::Error> {
|
||||
}
|
||||
|
||||
fn list_repos(directory: PathBuf) -> Result<(), std::io::Error> {
|
||||
let canonicalized = std::fs::canonicalize(directory)?;
|
||||
println!("Listing repositories under: {}", canonicalized.display().to_string().yellow());
|
||||
use std::fs;
|
||||
|
||||
let start = fs::canonicalize(directory)?;
|
||||
println!(
|
||||
"Listing repositories under: {}",
|
||||
start.display().to_string().yellow()
|
||||
);
|
||||
println!();
|
||||
|
||||
fn gather_repos(dir: &Path, recurse_level: usize) -> Result<Vec<PathBuf>, std::io::Error> {
|
||||
let mut repos = Vec::new();
|
||||
|
||||
let dir = fs::read_dir(dir)?;
|
||||
for entry in dir {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
let hidden = path
|
||||
.file_name()
|
||||
.map(|name| name.as_encoded_bytes())
|
||||
.and_then(|bytes| bytes.first())
|
||||
.map(|byte| *byte == b'.')
|
||||
.unwrap_or(false);
|
||||
|
||||
if let Ok(_repo) = Repository::open(&path) {
|
||||
repos.push(path);
|
||||
} else if path.is_dir() && !hidden {
|
||||
repos.extend(gather_repos(&path, recurse_level + 1)?.into_iter());
|
||||
}
|
||||
}
|
||||
Ok(repos)
|
||||
}
|
||||
|
||||
let repo_paths = gather_repos(&start, 0)?;
|
||||
for path in &repo_paths {
|
||||
println!("Repository: {}", path.display().to_string().yellow());
|
||||
/*
|
||||
let indent = recurse_level * INDENT_INCREMENT;
|
||||
print!("{: <1$}", "", indent);
|
||||
*/
|
||||
}
|
||||
|
||||
println!();
|
||||
println!("Total repos: {}", repo_paths.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user