Add remove command.

This commit is contained in:
Oleksandr Kozachuk
2022-12-04 01:14:18 +01:00
parent 9500a4f35c
commit afec096ff2
3 changed files with 9 additions and 2 deletions
+2
View File
@@ -14,6 +14,7 @@ peg::parser! {
/ error_cmd() / error_cmd()
/ ls_cmd() / ls_cmd()
/ mv_cmd() / mv_cmd()
/ rm_cmd()
/ comment_cmd() / comment_cmd()
) { c } ) { c }
@@ -65,6 +66,7 @@ peg::parser! {
rule add_cmd() -> Command<'input> = "a" _ name:name() { Command::Add(Rc::new(RefCell::new(name))) } rule add_cmd() -> Command<'input> = "a" _ name:name() { Command::Add(Rc::new(RefCell::new(name))) }
rule error_cmd() -> Command<'input> = "error" _ e:$(([' '..='~'])+) { Command::Error(LKErr::Error(e)) } rule error_cmd() -> Command<'input> = "error" _ e:$(([' '..='~'])+) { Command::Error(LKErr::Error(e)) }
rule mv_cmd() -> Command<'input> = "m" _ name:word() _ folder:word() { Command::Mv(name, folder) } rule mv_cmd() -> Command<'input> = "m" _ name:word() _ folder:word() { Command::Mv(name, folder) }
rule rm_cmd() -> Command<'input> = "r" _ name:word() { Command::Rm(name) }
rule comment_cmd() -> Command<'input> = "c" _ name:word() c:comment()? { Command::Comment(name, c) } rule comment_cmd() -> Command<'input> = "c" _ name:word() c:comment()? { Command::Comment(name, c) }
} }
} }
+6 -2
View File
@@ -105,7 +105,11 @@ impl<'a> LKEval<'a> {
} }
} }
None => out.push("error: password not found".to_string()), None => out.push("error: password not found".to_string()),
}, }
Command::Rm(name) => match self.state.borrow_mut().db.remove(name) {
Some(pwd) => out.push(format!("removed {}", pwd.borrow().name)),
None => out.push("error: password not found".to_string()),
}
Command::Help => { Command::Help => {
out.push("HELP".to_string()); out.push("HELP".to_string());
} }
@@ -131,7 +135,7 @@ impl<'a> LKEval<'a> {
LKErr::ParseError(e) => out.push(e.to_string()), LKErr::ParseError(e) => out.push(e.to_string()),
LKErr::ReadError(e) => out.push(e.to_string()), LKErr::ReadError(e) => out.push(e.to_string()),
LKErr::Error(e) => out.push(format!("error: {}", e.to_string())), LKErr::Error(e) => out.push(format!("error: {}", e.to_string())),
}, }
} }
LKPrint::new(out, quit, self.state.clone()) LKPrint::new(out, quit, self.state.clone())
+1
View File
@@ -15,6 +15,7 @@ pub enum Command<'a> {
Add(PasswordRef), Add(PasswordRef),
Ls, Ls,
Mv(Name, Name), Mv(Name, Name),
Rm(Name),
Comment(Name, Comment), Comment(Name, Comment),
Error(LKErr<'a>), Error(LKErr<'a>),
Help, Help,