diff --git a/src/app/args/structure.rs b/src/app/args/structure.rs index d2c4442..436676d 100644 --- a/src/app/args/structure.rs +++ b/src/app/args/structure.rs @@ -15,5 +15,9 @@ pub enum CommandArg { /// Helper command for installing asciidoctor-reveal-js InstallReveal, /// Starts a Webserver with the live preview of the Documentation - Serve + Serve { + /// Port for the Live Server + #[arg(short, long)] + port: Option + } } diff --git a/src/app/commands/serve.rs b/src/app/commands/serve.rs index 3b5bdff..8fac25c 100644 --- a/src/app/commands/serve.rs +++ b/src/app/commands/serve.rs @@ -10,9 +10,9 @@ use std::{env, path::Path}; use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status}; -pub async fn serve() { +pub async fn serve(port: Option) { build().await; - tokio::join!(watch_and_build(), start_server()); + tokio::join!(watch_and_build(), start_server(port)); } async fn watch_and_build() { @@ -21,10 +21,10 @@ async fn watch_and_build() { .expect("something went wrong") } -async fn start_server() { +async fn start_server(port: Option) { println!("\nServing at {} ", "http://localhost:8080".bold()); - let Ok(()) = listen("localhost", 8080, "./dist").await else { + let Ok(()) = listen("localhost", port.unwrap_or(8080), "./dist").await else { panic!("could not start server") }; } diff --git a/src/app/mod.rs b/src/app/mod.rs index 91a321a..15749d1 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -25,7 +25,7 @@ impl App { CommandArg::Build => build().await, CommandArg::Health => health(), CommandArg::InstallReveal => install_reveal().await, - CommandArg::Serve => serve().await + CommandArg::Serve { port } => serve(port).await }; }