|
|
@ -1,7 +1,7 @@ |
|
|
|
use clap::{Parser, Subcommand}; |
|
|
|
use clap::{Parser, Subcommand}; |
|
|
|
|
|
|
|
|
|
|
|
use std::fs; |
|
|
|
use std::fs; |
|
|
|
use std::io; |
|
|
|
use std::io::{self, Write}; |
|
|
|
use std::path::Path; |
|
|
|
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
|
|
|
|
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 git synchronization")] |
|
|
|
#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with git synchronization")] |
|
|
|
struct Cli { |
|
|
|
struct Cli { |
|
|
@ -59,6 +58,21 @@ fn init() -> io::Result<()> { |
|
|
|
Ok(()) |
|
|
|
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<()> { |
|
|
|
fn main() -> io::Result<()> { |
|
|
|
let cli = Cli::parse(); |
|
|
|
let cli = Cli::parse(); |
|
|
|
match &cli.command { |
|
|
|
match &cli.command { |
|
|
@ -67,7 +81,7 @@ fn main() -> io::Result<()> { |
|
|
|
println!("Initialization complete"); |
|
|
|
println!("Initialization complete"); |
|
|
|
} |
|
|
|
} |
|
|
|
Some(Commands::Add{..}) => { |
|
|
|
Some(Commands::Add{..}) => { |
|
|
|
println!("about to add new item"); |
|
|
|
add()?; |
|
|
|
} |
|
|
|
} |
|
|
|
None => { |
|
|
|
None => { |
|
|
|
if !is_inited() { |
|
|
|
if !is_inited() { |
|
|
|