added clap to configure port and interfaces, and fixed nixos module

This commit is contained in:
2026-03-26 19:33:30 +01:00
parent 81686d6fb8
commit 26b12e9dca
2 changed files with 132 additions and 115 deletions

View File

@@ -1,4 +1,5 @@
use axum::{Router, routing::get};
use clap::Parser;
use lazy_static::lazy_static;
use std::sync::Arc;
use tera::Tera;
@@ -20,12 +21,30 @@ lazy_static! {
};
}
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
/// Port to serve on
#[arg(short, long, default_value = "8000")]
port: String,
/// Whether to listen on 0.0.0.0
#[arg(short, long)]
host: bool,
/// Verbose mode
#[arg(short, long)]
verbose: bool,
}
struct AppState {
app_name: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
@@ -39,12 +58,10 @@ async fn main() -> anyhow::Result<()> {
.route("/showcase", get(showcase_handler))
.with_state(shared_state);
let host = false;
let port = "8000";
let addr = if host {
format!("0.0.0.0:{}", port)
let addr = if cli.host {
format!("0.0.0.0:{}", cli.port)
} else {
format!("127.0.0.1:{}", port)
format!("127.0.0.1:{}", cli.port)
};
let listener = tokio::net::TcpListener::bind(&addr).await?;