diff options
Diffstat (limited to 'sys/nixpkgs/pkgs/lf-make-map/src/main.rs')
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/main.rs | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/main.rs b/sys/nixpkgs/pkgs/lf-make-map/src/main.rs index dbfe5ec7..8a1ca602 100644 --- a/sys/nixpkgs/pkgs/lf-make-map/src/main.rs +++ b/sys/nixpkgs/pkgs/lf-make-map/src/main.rs @@ -1,14 +1,14 @@ use anyhow::Context; use clap::Parser; use cli::Args; -use generator::MappingsGenerator; +use log::trace; +use mapping::map_tree::MappingTree; +use walkdir::{DirEntry, WalkDir}; mod cli; -mod generator; mod mapping; -#[tokio::main] -async fn main() -> anyhow::Result<()> { +fn main() -> anyhow::Result<()> { let args = Args::parse(); stderrlog::new() @@ -20,14 +20,51 @@ async fn main() -> anyhow::Result<()> { .timestamp(stderrlog::Timestamp::Off) .init()?; - // gen_lf_mappings(args.home_name, 0, args.relevant_directories); - let map = MappingsGenerator::new(args.relevant_directories, args.depth, args.home_name) - .await - .context("Failed to initialize mappings generator")?; + let mut mappings = MappingTree::new(); + + for dir in args.relevant_directories { + for dir2 in WalkDir::new(&dir) + .max_depth(args.depth) + .into_iter() + .filter_entry(|e| is_dir(e)) + { + let directory = + dir2.with_context(|| format!("Failed to read dir ('{}')", &dir.display()))?; + + let path = directory + .path() + .strip_prefix(&args.home_name) + .with_context(|| { + format!( + "'{}' is not under the specified home path ('{}')!", + directory.path().display(), + args.home_name.display() + ) + })?; + + mappings.include(path.to_str().with_context(|| { + format!( + "\ +Can't derive a keymapping from path: '{}' \ +because it can't be turned to a string +", + path.display() + ) + })?); + + trace!("Processed '{}'..", directory.path().display()); + } + } + + println!("{}", mappings); Ok(()) } +fn is_dir(entry: &DirEntry) -> bool { + entry.file_type().is_dir() +} + // fn gen_lf_mappings(home_name: PathBuf, char_num: usize, rel_dirs: Vec<PathBuf>) { // let mut mappings_vec = vec![]; // let mut index_counter = 0; |