|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
use clap::{Parser, Subcommand}; |
|
|
|
|
|
|
|
|
|
use std::fs; |
|
|
|
|
use std::io; |
|
|
|
|
use std::io::{self, Write}; |
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -9,7 +9,6 @@ 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 git synchronization")] |
|
|
|
|
struct Cli { |
|
|
|
@ -59,6 +58,21 @@ fn init() -> io::Result<()> {
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn add() -> io::Result<()> { |
|
|
|
|
let mut file = match fs::OpenOptions::new() |
|
|
|
|
.write(true) |
|
|
|
|
.open(STORAGE_PATH) |
|
|
|
|
{ |
|
|
|
|
Ok(file) => file, |
|
|
|
|
Err(_) => { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::Other, "can`t open database")); // TODO: better error handling
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
writeln!(file, "new item")?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn main() -> io::Result<()> { |
|
|
|
|
let cli = Cli::parse(); |
|
|
|
|
match &cli.command { |
|
|
|
@ -67,7 +81,7 @@ fn main() -> io::Result<()> {
|
|
|
|
|
println!("Initialization complete"); |
|
|
|
|
} |
|
|
|
|
Some(Commands::Add{..}) => { |
|
|
|
|
println!("about to add new item"); |
|
|
|
|
add()?; |
|
|
|
|
} |
|
|
|
|
None => { |
|
|
|
|
if !is_inited() { |
|
|
|
|