🚧 Adds searching algorithm
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+11
-5
@@ -14,7 +14,7 @@ pub struct Item {
|
||||
pub type_: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct LoginItem {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
@@ -57,11 +57,14 @@ pub fn get_items() -> Result<Vec<Item>, Error> {
|
||||
}
|
||||
|
||||
pub fn get_login_items(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
let items = items.iter().filter(|item| item.type_ == "Login").collect::<Vec<&Item>>();
|
||||
let items = items
|
||||
.iter()
|
||||
.filter(|item| item.type_ == "Login")
|
||||
.collect::<Vec<&Item>>();
|
||||
let mut login_items = Vec::<LoginItem>::new();
|
||||
|
||||
for item in items {
|
||||
let password = sh::sh(format!("{} get '{}'", EXECUTABLE, item.name));
|
||||
let password = sh::sh(format!("{} get '{}'", EXECUTABLE, item.id));
|
||||
if let None = item.user {
|
||||
println!("WARNING: user not found for {}", item.name);
|
||||
}
|
||||
@@ -70,9 +73,12 @@ pub fn get_login_items(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
id: item.id.clone(),
|
||||
name: item.name.clone(),
|
||||
user: item.user.clone(),
|
||||
password: password,
|
||||
password: match password.strip_suffix("\n") {
|
||||
Some(s) => s.to_string(),
|
||||
None => password,
|
||||
},
|
||||
uris: item.uris.clone(),
|
||||
type_: item.type_.clone()
|
||||
type_: item.type_.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user