A small tool for storing passwords locally with git sync
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

use clap::{Parser, Subcommand};
use std::fs;
use std::io;
use std::path::Path;
4 months ago
const STORAGE_PATH: &str = "storage";
#[derive(Parser)]
#[command(name = "mps", version = "0.0.1", about = "MyPasswordStorage: Tool for storing your passwords locally with synchronization with git.")]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// Initialisation of storage and config, use this in first time of usage of mps
Init,
/// Adds new item with unique id to the db
Add {
#[arg(value_name="item_id")]
input: String
}
}
4 months ago
enum InitError {
Reinit,
BadInit
}
4 months ago
fn is_inited() -> bool {
let path = Path::new(STORAGE_PATH);
return path.exists();
}
4 months ago
fn init() -> Result<(), InitError> {
if is_inited() {
return Err(InitError::Reinit);
}
match fs::create_dir(STORAGE_PATH) {
Ok(_) => return Ok(()),
4 months ago
Err(_) => return Err(InitError::BadInit),
}
}
fn main() -> io::Result<()> {
let cli = Cli::parse();
match &cli.command {
Some(Commands::Init) => {
init().map_err(|e| match e {
4 months ago
InitError::Reinit => std::io::Error::new(std::io::ErrorKind::AlreadyExists, "Reinitialization attempted"),
InitError::BadInit => std::io::Error::new(std::io::ErrorKind::Other, "Bad initialization"),
})?;
println!("Initializing storage and config.");
}
Some(Commands::Add{..}) => {
println!("about to add new item");
}
None => {
println!("Will be here init or list if storage inited");
}
}
Ok(())
4 months ago
}