mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-21 20:18:06 +02:00
Added foundational modules for core functionalities:
- Introduced `walk.rs` as a parallel directory walker for search operations. - Implemented basic index handling in `commands/index.rs`. - Created `utils/config.rs` for configuration management with placeholders for future enhancements.
This commit is contained in:
commit
ab5558f537
16 changed files with 2187 additions and 0 deletions
31
src/utils/project.rs
Normal file
31
src/utils/project.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn get_project_info(
|
||||
project_path: &Path,
|
||||
config_dir: &Path,
|
||||
) -> Result<(String, PathBuf), Box<dyn std::error::Error>> {
|
||||
let project_name = project_path
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.ok_or("Unable to determine project name")?;
|
||||
|
||||
let db_name = sanitize_project_name(project_name);
|
||||
let db_path = config_dir.join(format!("{}.sqlite", db_name));
|
||||
|
||||
Ok((project_name.to_string(), db_path))
|
||||
}
|
||||
|
||||
pub fn sanitize_project_name(name: &str) -> String {
|
||||
name.to_lowercase()
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
' ' | '\t' | '\n' | '\r' => '_',
|
||||
c if c.is_alphanumeric() || c == '_' || c == '-' => c,
|
||||
_ => '_'
|
||||
})
|
||||
.collect::<String>()
|
||||
.split('_')
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("_")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue