From 76ff813f98a2657acdb5b448ab8af83993f9dc19 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Fri, 20 Sep 2024 08:42:53 +0000 Subject: [PATCH] init++ --- src/main.rs | 10 ++++++++-- src/storage.rs | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c2e001..07a9ed5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,13 @@ impl MPS { 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: where you installed your mps"); + println!("5. Run mps init"); + } fn prompt_new_password() -> io::Result { print!("Enter passphrase for storage: "); @@ -191,7 +198,6 @@ impl MPS { format!("Can`t find id: {}", id) )); } - let item = st.get(id); editor::open_to_show(&item.content)?; Ok(()) @@ -224,7 +230,7 @@ fn run_command() -> io::Result<()> { if !Storage::is_inited()? { match get_prompt("Do you want to init your storage?")? { PROMPT::YES => MPS::init()?, - PROMPT::NO => Storage::print_init_hint()?, + PROMPT::NO => MPS::print_init_hint(), } } else { let mut mps = MPS::new(); diff --git a/src/storage.rs b/src/storage.rs index 34f6e28..e553347 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -159,16 +159,17 @@ impl Storage { Ok(()) } - pub fn print_init_hint() -> io::Result<()> { - println!("mps can work only when storage inited."); - println!("Hint: you can restore your storage if you have it already:"); - println!(" git clone {}", Storage::get_storage_path()?); - println!("to init manually your storage and config"); - Ok(()) - } - pub fn is_inited() -> io::Result { - // TODO: check db + let sp = Storage::get_storage_path()?; + let storage_path = Path::new(&sp); + // Check if the folder exists and is a directory + if !storage_path.exists() || !storage_path.is_dir() { + return Err(io::Error::new( + io::ErrorKind::NotFound, + format!("{} does not exist or not a dir", Storage::get_storage_path()?) + )); + } + // TODO check git //let path = Path::new(&*STORAGE_FOLDER); //return path.exists();