|
|
@ -5,11 +5,13 @@ use std::io; |
|
|
|
use std::path::Path; |
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const STORAGE_PATH: &str = "storage"; |
|
|
|
const STORAGE_FOLDER: &str = "storage"; |
|
|
|
|
|
|
|
const STORAGE_PATH: &str = "storage/db.mps"; // TODO: concat from STORAGE_FOLDER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Parser)] |
|
|
|
#[derive(Parser)] |
|
|
|
#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with synchronization with git.")] |
|
|
|
#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with git synchronization")] |
|
|
|
struct Cli { |
|
|
|
struct Cli { |
|
|
|
#[command(subcommand)] |
|
|
|
#[command(subcommand)] |
|
|
|
command: Option<Commands>, |
|
|
|
command: Option<Commands>, |
|
|
@ -30,7 +32,7 @@ enum Commands { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn is_inited() -> bool { |
|
|
|
fn is_inited() -> bool { |
|
|
|
let path = Path::new(STORAGE_PATH); |
|
|
|
let path = Path::new(STORAGE_FOLDER); |
|
|
|
return path.exists(); |
|
|
|
return path.exists(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -38,13 +40,23 @@ fn init() -> io::Result<()> { |
|
|
|
if is_inited() { |
|
|
|
if is_inited() { |
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
} |
|
|
|
} |
|
|
|
match fs::create_dir(STORAGE_PATH) { |
|
|
|
match fs::create_dir(STORAGE_FOLDER) { |
|
|
|
Ok(_) => { |
|
|
|
Ok(_) => { |
|
|
|
println!("Initialization complete"); |
|
|
|
println!("Create folder for storage"); // TODO: make it only in debug mode
|
|
|
|
return Ok(()); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Bad initialization")), |
|
|
|
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Can`t create storage folder")), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match fs::File::create(STORAGE_PATH) { |
|
|
|
|
|
|
|
Ok(_) => { |
|
|
|
|
|
|
|
println!("Storage db created"); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Err(_) => { |
|
|
|
|
|
|
|
return Err(io::Error::new(io::ErrorKind::Other, "Can`t create mps.db")); // TODO: better error, not just Other
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn main() -> io::Result<()> { |
|
|
|
fn main() -> io::Result<()> { |
|
|
@ -73,7 +85,6 @@ fn main() -> io::Result<()> { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
println!("login, not implemented yet") |
|
|
|
println!("login, not implemented yet") |
|
|
|
} |
|
|
|
} |
|
|
|
println!("Will be here init or list if storage inited"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|