Simplify moar

This commit is contained in:
Silas Brack 2026-03-07 13:23:38 +01:00
parent 7f3ec69cf6
commit 07490efc28
14 changed files with 261 additions and 1061 deletions

View file

@ -1,11 +1,16 @@
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "mkv", about = "Distributed key-value store")]
struct Cli {
#[arg(short, long, default_value = "config.toml")]
config: PathBuf,
#[arg(short, long, default_value = "/tmp/mkv/index.db")]
db: String,
#[arg(short, long, required = true, value_delimiter = ',')]
volumes: Vec<String>,
#[arg(short, long, default_value_t = 2)]
replicas: usize,
#[command(subcommand)]
command: Commands,
@ -14,7 +19,10 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Start the index server
Serve,
Serve {
#[arg(short, long, default_value_t = 3000)]
port: u16,
},
/// Rebuild SQLite index from volume servers
Rebuild,
/// Rebalance data after adding/removing volumes
@ -27,28 +35,27 @@ enum Commands {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let cli = Cli::parse();
let config = mkv::config::Config::load(&cli.config).unwrap_or_else(|e| {
eprintln!("Failed to load config: {e}");
std::process::exit(1);
});
let args = mkv::Args {
db_path: cli.db,
volumes: cli.volumes,
replicas: cli.replicas,
};
match cli.command {
Commands::Serve => {
let port = config.server.port;
let app = mkv::build_app(config).await;
Commands::Serve { port } => {
let app = mkv::build_app(&args);
let addr = format!("0.0.0.0:{port}");
tracing::info!("Listening on {addr}");
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Commands::Rebuild => {
mkv::rebuild::run(&config).await;
mkv::rebuild::run(&args).await;
}
Commands::Rebalance { dry_run } => {
mkv::rebalance::run(&config, dry_run).await;
mkv::rebalance::run(&args, dry_run).await;
}
}
}