added optional port as argument

This commit is contained in:
2023-03-13 00:35:31 +01:00
parent da5046bfc0
commit 4220467625
3 changed files with 10 additions and 6 deletions

View File

@@ -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<u16>
}
}

View File

@@ -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<u16>) {
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<u16>) {
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")
};
}

View File

@@ -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
};
}