|
|
|
@ -65,8 +65,8 @@ fn get_prompt(question: &str) -> io::Result<PROMPT> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: change password functionality
|
|
|
|
|
// TODO: return storage inited
|
|
|
|
|
fn login() -> io::Result<String> { |
|
|
|
|
// TODO: check if inited
|
|
|
|
|
print!("Enter passphrase for storage: "); |
|
|
|
|
io::stdout().flush()?; |
|
|
|
|
// TODO: check in db
|
|
|
|
@ -75,6 +75,8 @@ fn login() -> io::Result<String> {
|
|
|
|
|
if password != "pass" { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidData, "Wrong passphrase")); |
|
|
|
|
} |
|
|
|
|
print!("\x1B[1A\x1B[2K"); // Move cursor up one line and clear that line
|
|
|
|
|
io::stdout().flush()?; // Ensure the changes are reflected immediately
|
|
|
|
|
Ok(String::from(password)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -100,12 +102,11 @@ fn init() -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn list() -> io:: Result<()> { |
|
|
|
|
// TODO: get storage from login
|
|
|
|
|
let passphrase = login()?; |
|
|
|
|
let st = Storage::from_db(passphrase)?; |
|
|
|
|
let mut vec: Vec<_> = st.items.iter().collect(); |
|
|
|
|
vec.sort(); |
|
|
|
|
for item in &vec { |
|
|
|
|
println!("{}", item.id); |
|
|
|
|
for id in st.ids() { |
|
|
|
|
println!("{}", id); |
|
|
|
|
} |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
@ -123,7 +124,7 @@ fn add(id: &String) -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let content = editor::open_to_edit()?; |
|
|
|
|
st.items.insert(Item::from(id.clone(), content)); |
|
|
|
|
st.add(Item::from(id.clone(), content)); |
|
|
|
|
st.dump()?; |
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
@ -140,7 +141,7 @@ fn show(id: &String) -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let item = st.get(id); |
|
|
|
|
editor::open_to_show(&item.content); |
|
|
|
|
editor::open_to_show(&item.content)?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -166,8 +167,7 @@ fn run_command() -> io::Result<()> {
|
|
|
|
|
PROMPT::NO => Storage::print_init_hint(), |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
login()?; |
|
|
|
|
// TODO: list()
|
|
|
|
|
list()? |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|