Browse Source

storae db

db-refactoring
Coin de Gamma 4 months ago
parent
commit
e2dd62ad6b
  1. 27
      src/main.rs

27
src/main.rs

@ -5,11 +5,13 @@ use std::io;
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)]
#[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 {
#[command(subcommand)]
command: Option<Commands>,
@ -30,7 +32,7 @@ enum Commands {
}
fn is_inited() -> bool {
let path = Path::new(STORAGE_PATH);
let path = Path::new(STORAGE_FOLDER);
return path.exists();
}
@ -38,13 +40,23 @@ fn init() -> io::Result<()> {
if is_inited() {
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted"));
}
match fs::create_dir(STORAGE_PATH) {
match fs::create_dir(STORAGE_FOLDER) {
Ok(_) => {
println!("Initialization complete");
return Ok(());
println!("Create folder for storage"); // TODO: make it only in debug mode
},
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<()> {
@ -73,7 +85,6 @@ fn main() -> io::Result<()> {
} else {
println!("login, not implemented yet")
}
println!("Will be here init or list if storage inited");
}
}
Ok(())

Loading…
Cancel
Save