added optional port as argument
This commit is contained in:
@@ -15,5 +15,9 @@ pub enum CommandArg {
|
|||||||
/// Helper command for installing asciidoctor-reveal-js
|
/// Helper command for installing asciidoctor-reveal-js
|
||||||
InstallReveal,
|
InstallReveal,
|
||||||
/// Starts a Webserver with the live preview of the Documentation
|
/// Starts a Webserver with the live preview of the Documentation
|
||||||
Serve
|
Serve {
|
||||||
|
/// Port for the Live Server
|
||||||
|
#[arg(short, long)]
|
||||||
|
port: Option<u16>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ use std::{env, path::Path};
|
|||||||
use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status};
|
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;
|
build().await;
|
||||||
tokio::join!(watch_and_build(), start_server());
|
tokio::join!(watch_and_build(), start_server(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn watch_and_build() {
|
async fn watch_and_build() {
|
||||||
@@ -21,10 +21,10 @@ async fn watch_and_build() {
|
|||||||
.expect("something went wrong")
|
.expect("something went wrong")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_server() {
|
async fn start_server(port: Option<u16>) {
|
||||||
println!("\nServing at {} ", "http://localhost:8080".bold());
|
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")
|
panic!("could not start server")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ impl App {
|
|||||||
CommandArg::Build => build().await,
|
CommandArg::Build => build().await,
|
||||||
CommandArg::Health => health(),
|
CommandArg::Health => health(),
|
||||||
CommandArg::InstallReveal => install_reveal().await,
|
CommandArg::InstallReveal => install_reveal().await,
|
||||||
CommandArg::Serve => serve().await
|
CommandArg::Serve { port } => serve(port).await
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user