From bb7da4934d4a5f0f5184ea382a122724d27d88a4 Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sun, 13 Jun 2021 11:03:27 -0600 Subject: power up CLI --- src/cli/mod.rs | 23 +++++++++++++++++++++++ src/cli/run_server.rs | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/cli/mod.rs create mode 100644 src/cli/run_server.rs (limited to 'src/cli') diff --git a/src/cli/mod.rs b/src/cli/mod.rs new file mode 100644 index 0000000..c656c1c --- /dev/null +++ b/src/cli/mod.rs @@ -0,0 +1,23 @@ +use structopt::StructOpt; + +use crate::{Settings, UrlMap}; + +mod run_server; + +#[derive(StructOpt)] +enum Command { + RunServer(run_server::RunServer), +} + +impl Command { + fn execute(self, urls: UrlMap, settings: Settings) { + match self { + Command::RunServer(command) => command.execute(urls, settings), + } + } +} + +pub fn main(urls: UrlMap, settings: Settings) { + let command = Command::from_args(); + command.execute(urls, settings); +} diff --git a/src/cli/run_server.rs b/src/cli/run_server.rs new file mode 100644 index 0000000..9e4d91c --- /dev/null +++ b/src/cli/run_server.rs @@ -0,0 +1,20 @@ +use structopt::StructOpt; + +use crate::{Settings, UrlMap}; + +#[derive(StructOpt)] +pub struct RunServer { + +} + +impl RunServer { + pub fn execute(self, urls: UrlMap, _settings: Settings) { + let server_task = warp::serve(urls).run(([127, 0, 0, 1], 3030)); + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(server_task) + } +} -- cgit v1.2.3