Skip to content

Commit

Permalink
Merge pull request #4 from mdzk-rs/issue-3
Browse files Browse the repository at this point in the history
added the flags `port` and `bind` to the `serve` subcommand
  • Loading branch information
ratsclub authored Aug 6, 2021
2 parents 4f0b47a + c0e3948 commit 033c071
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ enum Command {
#[structopt(name = "serve")]
Serve {
#[structopt(parse(from_os_str))]
dir: Option<PathBuf>
dir: Option<PathBuf>,

#[structopt(long="port", short="p", default_value="3000")]
port: i32,

#[structopt(long="bind", short="b", default_value="localhost")]
bind: String,
},
}

Expand All @@ -36,6 +42,6 @@ fn main() -> Result<(), Error> {
match args.cmd {
Command::Build{dir} => build(dir),
Command::Init{dir} => init(dir),
Command::Serve{dir} => serve(dir),
Command::Serve{dir, port, bind} => serve(dir, port, bind),
}
}
6 changes: 2 additions & 4 deletions src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ use toml;
/// The HTTP endpoint for the websocket used to trigger reloads when a file changes.
const LIVE_RELOAD_ENDPOINT: &str = "__livereload";

pub fn serve(dir: Option<PathBuf>) -> Result<(), Error> {
pub fn serve(dir: Option<PathBuf>, port: i32, bind: String) -> Result<(), Error> {
let mut zk = init_zk(dir)?;

zk.with_preprocessor(KatexProcessor);
zk.with_preprocessor(Backlinks);
zk.with_preprocessor(WikiLinks);

let port = "3000";
let hostname = "localhost";
// let open_browser = false;

let address = format!("{}:{}", hostname, port);
let address = format!("{}:{}", bind, port.to_string());

let livereload_url = format!("ws://{}/{}", address, LIVE_RELOAD_ENDPOINT);
let update_config = |book: &mut MDBook| {
Expand Down

0 comments on commit 033c071

Please sign in to comment.