aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/cli/mod.rs23
-rw-r--r--src/cli/run_server.rs20
-rw-r--r--src/lib.rs7
-rw-r--r--src/server.rs11
5 files changed, 46 insertions, 16 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cc6e98f..7c0c675 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,5 +8,6 @@ edition = "2018"
[dependencies]
hyper = { version = "0.14", features = ["full"] }
+structopt = "0.3.21"
tokio = { version = "1", features = ["full"] }
warp = "0.3"
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)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 112ed57..38ae0e2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,16 +1,13 @@
+mod cli;
pub mod contrib;
pub mod http;
-pub mod server;
pub mod settings;
pub mod urls;
+pub use cli::main;
pub use settings::Settings;
pub use urls::UrlMap;
-pub fn main(urls: UrlMap, settings: Settings) {
- todo!()
-}
-
#[macro_export]
macro_rules! main {
($urls:expr, $settings:expr) => {
diff --git a/src/server.rs b/src/server.rs
deleted file mode 100644
index b275616..0000000
--- a/src/server.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use crate::urls::UrlMap;
-
-pub fn run_server(filter_stack: UrlMap) {
- let server_task = warp::serve(filter_stack).run(([127, 0, 0, 1], 3030));
-
- tokio::runtime::Builder::new_multi_thread()
- .enable_all()
- .build()
- .unwrap()
- .block_on(server_task)
-}