mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-09 19:45:13 +02:00
Refactor project and index handling
- Standardized formatting across key functions in `project.rs`. - Updated `index::handle` and `build_index` to incorporate the `config` parameter. - Improved index-building logic to include project details and enhanced issue tracking. - Replaced variable names like `files` with `paths` for clarity in `scan.rs`.
This commit is contained in:
parent
0eecf886f2
commit
ead64c0bd3
4 changed files with 66 additions and 36 deletions
|
|
@ -3,29 +3,29 @@ 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))
|
||||
) -> 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("_")
|
||||
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