From a4a9c2afd0c0773b5fdfea19283ffe72011dafef Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Mon, 12 Dec 2022 12:58:26 +0100 Subject: [PATCH] Refactor ls command, to use password structure for sorting, also required for ls cache. --- src/repl.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/repl.rs b/src/repl.rs index 5ddaf41..264ae20 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -4,7 +4,7 @@ use std::{cell::RefCell, rc::Rc}; use crate::lk::LK; use crate::parser::command_parser; -use crate::password::fix_password_recursion; +use crate::password::{PasswordRef, fix_password_recursion}; use crate::structs::{Command, LKErr, Radix}; #[derive(Debug)] @@ -75,14 +75,14 @@ impl<'a> LKEval<'a> { } fn cmd_ls(&mut self, out: &mut Vec) { - let mut tmp: Vec = vec![]; + let mut tmp: Vec = vec![]; 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; - for line in tmp { - out.push(format!("{:>3} {}", Radix::new(counter, 36).unwrap().to_string(), line)); + for pwd in tmp { + out.push(format!("{:>3} {}", Radix::new(counter, 36).unwrap().to_string(), pwd.borrow().to_string())); counter += 1; } }