with args

This commit is contained in:
2022-10-14 22:39:16 +02:00
parent cb3bd469db
commit 10c34c7827
4 changed files with 187 additions and 7 deletions

View File

@@ -1,12 +1,31 @@
use std::{path::PathBuf, string};
use std::path::PathBuf;
use clap::Parser;
#[derive(clap::Parser, Clone)]
struct Args {
#[arg(long)]
root_dir: String,
#[arg(long)]
pattern: Option<String>,
#[arg(long)]
projects_file: String,
}
fn main() -> eyre::Result<()> {
let args = Args::parse();
// Choose dir
let root_dir = "/home/kjuulh/git/";
let root_dir = args.root_dir;
let mut projects: Vec<PathBuf> = vec![];
let pattern = regex::Regex::new(".*\\.git$")?;
let pattern = regex::Regex::new(match args.pattern {
Some(p) => Box::leak(p.into_boxed_str()),
None => ".*\\.git$",
})?;
// Look for dir .git if found add path to map
for entry in walkdir::WalkDir::new(root_dir)
@@ -35,10 +54,7 @@ fn main() -> eyre::Result<()> {
.collect::<Vec<String>>();
let content = projects_str.join("\n");
std::fs::write(
"/home/kjuulh/.local/share/nvim/project_nvim/project_history",
content,
)?;
std::fs::write(args.projects_file, content)?;
Ok(())
}