aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-26 22:08:50 -0700
committerFuwn <[email protected]>2021-05-26 22:08:50 -0700
commiteeee37edf5affadda15825e6b3b0e9bc8a95a8bb (patch)
treea181c68362bd064a423fc0e89cb5f51e4ce939a8
parentrefactor(whirl): move environment setup, execute doesn't take matches (diff)
downloadwhirl-eeee37edf5affadda15825e6b3b0e9bc8a95a8bb.tar.xz
whirl-eeee37edf5affadda15825e6b3b0e9bc8a95a8bb.zip
refactor(whirl): move cli subcommand executor to cli struct
-rw-r--r--crates/whirl/src/cli.rs49
-rw-r--r--crates/whirl/src/lib.rs1
-rw-r--r--crates/whirl/src/subs.rs49
3 files changed, 46 insertions, 53 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs
index 0f07690..a909c9f 100644
--- a/crates/whirl/src/cli.rs
+++ b/crates/whirl/src/cli.rs
@@ -2,9 +2,15 @@
// SPDX-License-Identifier: GPL-3.0-only
use structopt::clap::{App, AppSettings, Arg, SubCommand};
+use whirl_api::Api;
use whirl_config::Config;
-
-use crate::subs::run;
+use whirl_prompt::Prompt;
+use whirl_server::{
+ distributor::Distributor,
+ hub::Hub,
+ Server,
+ ServerType::{AutoServer, RoomServer},
+};
pub struct Cli;
impl Cli {
@@ -20,7 +26,7 @@ impl Cli {
}
match matches.subcommand() {
- ("run", _) => run().await,
+ ("run", _) => Self::run().await,
("config", Some(s_matches)) =>
match s_matches.subcommand() {
("show", _) => println!("{:#?}", Config::get()),
@@ -64,4 +70,41 @@ impl Cli {
Arg::with_name("trace").short("t").long("trace"),
])
}
+
+ async fn run() {
+ let (tx, _rx) = std::sync::mpsc::channel();
+
+ let _threads = vec![
+ tokio::spawn(async move {
+ let _ = Distributor::listen(
+ &*format!("0.0.0.0:{}", Config::get().distributor.port),
+ AutoServer,
+ )
+ .await;
+ }),
+ tokio::spawn(async move {
+ let _ = Hub::listen(&*format!("0.0.0.0:{}", Config::get().hub.port), RoomServer).await;
+ }),
+ tokio::spawn(async move {
+ let _ = Api::listen(
+ tx,
+ &*format!("0.0.0.0:{}", Config::get().whirlsplash.api.port),
+ )
+ .await;
+ }),
+ ];
+
+ if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true"
+ || !Config::get().whirlsplash.prompt.enable
+ {
+ info!("starting with prompt disabled");
+ loop {
+ std::thread::sleep(std::time::Duration::default());
+ }
+ } else {
+ Prompt::handle().await;
+ }
+
+ // actix_web::rt::System::new("").block_on(rx.recv().unwrap().stop(true));
+ }
}
diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs
index 9ef177c..10061fd 100644
--- a/crates/whirl/src/lib.rs
+++ b/crates/whirl/src/lib.rs
@@ -25,5 +25,4 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
pub mod cli;
-pub mod subs;
pub mod whirl;
diff --git a/crates/whirl/src/subs.rs b/crates/whirl/src/subs.rs
deleted file mode 100644
index 08da4d6..0000000
--- a/crates/whirl/src/subs.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use whirl_api::Api;
-use whirl_config::Config;
-use whirl_prompt::Prompt;
-use whirl_server::{
- distributor::Distributor,
- hub::Hub,
- Server,
- ServerType::{AutoServer, RoomServer},
-};
-
-pub async fn run() {
- let (tx, _rx) = std::sync::mpsc::channel();
-
- let _threads = vec![
- tokio::spawn(async move {
- let _ = Distributor::listen(
- &*format!("0.0.0.0:{}", Config::get().distributor.port),
- AutoServer,
- )
- .await;
- }),
- tokio::spawn(async move {
- let _ = Hub::listen(&*format!("0.0.0.0:{}", Config::get().hub.port), RoomServer).await;
- }),
- tokio::spawn(async move {
- let _ = Api::listen(
- tx,
- &*format!("0.0.0.0:{}", Config::get().whirlsplash.api.port),
- )
- .await;
- }),
- ];
-
- if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true"
- || !Config::get().whirlsplash.prompt.enable
- {
- info!("starting with prompt disabled");
- loop {
- std::thread::sleep(std::time::Duration::default());
- }
- } else {
- Prompt::handle().await;
- }
-
- // actix_web::rt::System::new("").block_on(rx.recv().unwrap().stop(true));
-}