Browse Source

init++

fix-typo
Coin de Gamma 3 months ago
parent
commit
76ff813f98
  1. 10
      src/main.rs
  2. 17
      src/storage.rs

10
src/main.rs

@ -78,6 +78,13 @@ impl MPS {
MPS { storage: None } MPS { storage: None }
} }
fn print_init_hint() {
println!("1. Create empty repository for storing your passwords on gitlab or somewhere you prefer");
println!("2. Clone to your home folder ~/.mps/storage");
println!("3. Set variable $MPS_HOME=\"~/.mps/\"");
println!("4. Add to your $PATH:<path_to_msp> where you installed your mps");
println!("5. Run mps init");
}
fn prompt_new_password() -> io::Result<String> { fn prompt_new_password() -> io::Result<String> {
print!("Enter passphrase for storage: "); print!("Enter passphrase for storage: ");
@ -191,7 +198,6 @@ impl MPS {
format!("Can`t find id: {}", id) format!("Can`t find id: {}", id)
)); ));
} }
let item = st.get(id); let item = st.get(id);
editor::open_to_show(&item.content)?; editor::open_to_show(&item.content)?;
Ok(()) Ok(())
@ -224,7 +230,7 @@ fn run_command() -> io::Result<()> {
if !Storage::is_inited()? { if !Storage::is_inited()? {
match get_prompt("Do you want to init your storage?")? { match get_prompt("Do you want to init your storage?")? {
PROMPT::YES => MPS::init()?, PROMPT::YES => MPS::init()?,
PROMPT::NO => Storage::print_init_hint()?, PROMPT::NO => MPS::print_init_hint(),
} }
} else { } else {
let mut mps = MPS::new(); let mut mps = MPS::new();

17
src/storage.rs

@ -159,16 +159,17 @@ impl Storage {
Ok(()) Ok(())
} }
pub fn print_init_hint() -> io::Result<()> { pub fn is_inited() -> io::Result<bool> {
println!("mps can work only when storage inited."); let sp = Storage::get_storage_path()?;
println!("Hint: you can restore your storage if you have it already:"); let storage_path = Path::new(&sp);
println!(" git clone <your_storage_git_url> {}", Storage::get_storage_path()?); // Check if the folder exists and is a directory
println!("to init manually your storage and config"); if !storage_path.exists() || !storage_path.is_dir() {
Ok(()) return Err(io::Error::new(
io::ErrorKind::NotFound,
format!("{} does not exist or not a dir", Storage::get_storage_path()?)
));
} }
pub fn is_inited() -> io::Result<bool> {
// TODO: check db
// TODO check git // TODO check git
//let path = Path::new(&*STORAGE_FOLDER); //let path = Path::new(&*STORAGE_FOLDER);
//return path.exists(); //return path.exists();

Loading…
Cancel
Save