mod base62;
mod key;
mod server;
mod store;
use std::path::PathBuf;
use anyhow::Result;
use clap::{command, Parser};
use crate::server::Server;
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Args {
#[arg(global = true, long, short, env, default_value_t = 8080)]
port: u16,
#[arg(global = true, long, env)]
db_path: Option<PathBuf>,
}
pub struct Bref {
port: u16,
db_path: PathBuf,
}
impl Bref {
pub async fn run(self) -> Result<()> {
Server::new(self.port, self.db_path).listen().await
}
}
impl Default for Bref {
fn default() -> Self {
Self::from(Args::parse())
}
}
impl From<Args> for Bref {
fn from(args: Args) -> Self {
let db_path = args.db_path.unwrap_or_else(|| {
xdg::BaseDirectories::with_prefix("bref")
.unwrap()
.get_data_dirs()
.first()
.unwrap()
.to_owned()
});
Self {
port: args.port,
db_path,
}
}
}