summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a1893b7..515f7c1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,4 @@
+mod args;
mod config;
mod errors;
mod handlers;
@@ -8,22 +9,34 @@ pub use errors::{Error, Result};
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
use axum::{Router, routing::get};
+use clap::Parser;
use tokio::net::TcpListener;
use tower_http::services::ServeFile;
-pub async fn run() -> Result<()> {
- let config = config::Config::new()?;
+use args::{Cli, Command};
+use config::Config;
- let app = Router::new()
+pub fn app(config: Config) -> Router {
+ Router::new()
.nest_service("/static/style.css", ServeFile::new(&config.style_file))
.nest_service("/static/favicon.svg", ServeFile::new(&config.favicon_file))
.route("/", get(handlers::handler))
- .with_state(config.clone());
+ .with_state(config)
+}
+
+pub async fn run() -> Result<()> {
+ let args = Cli::parse();
+
+ let config = config::Config::new()?;
- let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), config.port);
- let listener = TcpListener::bind(socket).await?;
+ match args.command {
+ Command::Serv => {
+ let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), config.port);
+ let listener = TcpListener::bind(socket).await?;
- axum::serve(listener, app).await?;
+ axum::serve(listener, app(config.clone())).await?;
+ }
+ }
Ok(())
}