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