Refactor ls command, to use password structure for sorting, also required for ls cache.

This commit is contained in:
Oleksandr Kozachuk
2022-12-12 12:58:26 +01:00
parent 5ad06ecf5b
commit a4a9c2afd0
+6 -6
View File
@@ -4,7 +4,7 @@ use std::{cell::RefCell, rc::Rc};
use crate::lk::LK; use crate::lk::LK;
use crate::parser::command_parser; use crate::parser::command_parser;
use crate::password::fix_password_recursion; use crate::password::{PasswordRef, fix_password_recursion};
use crate::structs::{Command, LKErr, Radix}; use crate::structs::{Command, LKErr, Radix};
#[derive(Debug)] #[derive(Debug)]
@@ -75,14 +75,14 @@ impl<'a> LKEval<'a> {
} }
fn cmd_ls(&mut self, out: &mut Vec<String>) { fn cmd_ls(&mut self, out: &mut Vec<String>) {
let mut tmp: Vec<String> = vec![]; let mut tmp: Vec<PasswordRef> = vec![];
for (_, name) in &self.state.borrow().db { for (_, name) in &self.state.borrow().db {
tmp.push(name.borrow().to_string()); tmp.push(name.clone());
} }
tmp.sort(); tmp.sort_by(|a, b| a.borrow().name.cmp(&b.borrow().name));
let mut counter = 1; let mut counter = 1;
for line in tmp { for pwd in tmp {
out.push(format!("{:>3} {}", Radix::new(counter, 36).unwrap().to_string(), line)); out.push(format!("{:>3} {}", Radix::new(counter, 36).unwrap().to_string(), pwd.borrow().to_string()));
counter += 1; counter += 1;
} }
} }