#![feature(iterator_try_collect)] #![feature(never_type)] pub mod server; use clap::{Parser, Subcommand}; use serde::Deserialize; use server::server; use std::{fs::read_to_string, net::SocketAddr, path::PathBuf}; pub type Serial = u64; #[derive(Parser)] struct Args { config: PathBuf, #[clap(subcommand)] action: Action, } #[derive(Subcommand)] enum Action { Daemon, Restore { id: String, destination: PathBuf }, Backup { path: PathBuf }, } #[derive(Deserialize)] pub struct Config { storage: StorageConfig, server: ServerConfig, peer: Vec, } #[derive(Deserialize)] pub struct PeerConfig { name: String, address: SocketAddr, shared_secret: String, } #[derive(Deserialize)] pub struct ServerConfig { address: String, } #[derive(Deserialize)] pub struct StorageConfig { root: PathBuf, size: u64, versions: usize, upload_cooldown: u64, download_cooldown: u64, upload_speed: usize, download_speed: usize, } fn main() -> anyhow::Result<()> { env_logger::init_from_env("LOG"); let args = Args::parse(); let config = read_to_string(&args.config)?; let config = toml::from_str::(&config)?; match args.action { Action::Daemon => server(config.into())?, Action::Restore { id, destination } => todo!(), Action::Backup { path } => todo!(), } Ok(()) }