Split project into three workspaces: hel (the library), helcli (the tool) and helwasm (the wasm code). Move wasm incompatible code to extra modules in utils.rs to be implementable separately for wasm.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
use crate::password::{fix_password_recursion, Name, PasswordRef};
|
||||
use regex::{Captures, Regex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct LK {
|
||||
pub db: HashMap<Name, PasswordRef>,
|
||||
pub ls: HashMap<String, PasswordRef>,
|
||||
pub secrets: HashMap<Name, String>,
|
||||
}
|
||||
|
||||
impl LK {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
db: HashMap::new(),
|
||||
ls: HashMap::new(),
|
||||
secrets: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fix_hierarchy(&self) {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"\s*\^([!-~]+)").unwrap();
|
||||
}
|
||||
for db in vec![&self.db, &self.ls] {
|
||||
for (_, name) in db {
|
||||
let comment = name.borrow().comment.clone();
|
||||
match comment {
|
||||
Some(comment) => {
|
||||
let mut changed = false;
|
||||
let new = RE
|
||||
.replace(comment.as_str(), |c: &Captures| {
|
||||
let folder = c[1].to_string();
|
||||
match self.db.get(&folder) {
|
||||
Some(entry) => {
|
||||
name.borrow_mut().parent = Some(entry.clone());
|
||||
changed = true;
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
""
|
||||
})
|
||||
.trim()
|
||||
.to_string();
|
||||
if changed && new != comment {
|
||||
name.borrow_mut().comment = if new.len() > 0 { Some(new) } else { None }
|
||||
}
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
fix_password_recursion(name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user