diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/src/repl.rs b/src/repl.rs index 8fdcc20..0c0a6b0 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -64,12 +64,7 @@ impl<'a> LKEval<'a> { }, Command::Ls => { for (_, name) in &self.state.borrow().db { - let pw = name.borrow(); - let prefix = match pw.prefix.as_ref() { Some(s) => format!("{} ", s), None => "".to_string() }; - let length = match pw.length { Some(l) => format!("{}", l), None => "".to_string() }; - let comment = match pw.comment.as_ref() { Some(s) => format!(" {}", s), None => "".to_string() }; - let parent = match &pw.parent { Some(s) => format!(" ^{}", s.borrow().name), None => "".to_string() }; - out.push(format!("{}{} {}{} {} {}{}{}", prefix, pw.name, length, pw.mode, pw.seq, pw.date, comment, parent)); + out.push(name.borrow().to_string()); } }, Command::Add(name) => { diff --git a/src/structs.rs b/src/structs.rs index 60671e2..23a7956 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -55,17 +55,27 @@ pub struct LK { impl std::fmt::Display for Mode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Mode::Regular => write!(f, "R"), - Mode::RegularUpcase => write!(f, "UR"), - Mode::NoSpace => write!(f, "N"), - Mode::NoSpaceUpcase => write!(f, "UN"), - Mode::Hex => write!(f, "H"), - Mode::HexUpcase => write!(f, "UH"), - Mode::Base64 => write!(f, "B"), - Mode::Base64Upcase => write!(f, "UB"), - Mode::Decimal => write!(f, "D"), - } + write!(f, "{}", match self { + Mode::Regular => "R", + Mode::RegularUpcase => "UR", + Mode::NoSpace => "N", + Mode::NoSpaceUpcase => "UN", + Mode::Hex => "H", + Mode::HexUpcase => "UH", + Mode::Base64 => "B", + Mode::Base64Upcase => "UB", + Mode::Decimal => "D", + }.to_string()) + } +} + +impl std::string::ToString for Password { + fn to_string(&self) -> String { + let prefix = match self.prefix.as_ref() { Some(s) => format!("{} ", s), None => "".to_string() }; + let length = match self.length { Some(l) => format!("{}", l), None => "".to_string() }; + let comment = match self.comment.as_ref() { Some(s) => format!(" {}", s), None => "".to_string() }; + let parent = match &self.parent { Some(s) => format!(" ^{}", s.borrow().name), None => "".to_string() }; + format!("{}{} {}{} {} {}{}{}", prefix, self.name, length, self.mode, self.seq, self.date, comment, parent) } }