diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 7fa1bda..35728a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,36 @@ +use std::path::{Path, PathBuf}; +use serde::Deserialize; +use structopt::StructOpt; use warp::Filter; +#[derive(Debug, Deserialize)] +struct Config { + port: u16, +} + +#[derive(Debug, StructOpt)] +#[structopt(name = "ewww", about = "Web server for static sites")] +struct Opt { + #[structopt(parse(from_os_str))] + config: PathBuf, +} + #[tokio::main] async fn main() { + let opt = Opt::from_args(); + let config = read_config(&opt.config).unwrap(); + let hello = warp::any() .map(|| "hello, world\n".to_string()); + eprintln!("starting server: {:?}", config); warp::serve(hello) - .run(([127, 0, 0, 1], 3030)) + .run(([127, 0, 0, 1], config.port)) .await; } + +fn read_config(filename: &Path) -> anyhow::Result<Config> { + let config = std::fs::read_to_string(filename)?; + let config: Config = serde_yaml::from_str(&config)?; + Ok(config) +} |