about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/lf-make-map/src/main.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-06 18:09:03 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-06 18:09:03 +0200
commit5a27c1fff017f73b41267873ecb01da253030e9f (patch)
tree8d4bb7b95a30968819109a4c1a6624072189d732 /sys/nixpkgs/pkgs/lf-make-map/src/main.rs
parentfeat(pkgs/lf-make-map): Change the key to custom type and add visuals (diff)
downloadnixos-config-5a27c1fff017f73b41267873ecb01da253030e9f.zip
feat(pkgs/lf-make-map): Implement all needed details to produce first mappings
The only bug left right know, is that multiple same mappings can be
generated because of the ways the types interact with each other.
Diffstat (limited to 'sys/nixpkgs/pkgs/lf-make-map/src/main.rs')
-rw-r--r--sys/nixpkgs/pkgs/lf-make-map/src/main.rs53
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;