|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
use anyhow::Context;
|
|
|
use anyhow::Context;
|
|
|
use clap::{App, Arg};
|
|
|
use clap::{App, Arg};
|
|
|
use crossbeam_channel;
|
|
|
use crossbeam_channel;
|
|
|
@ -20,16 +22,15 @@ mod room; |
|
|
mod testing;
|
|
|
mod testing;
|
|
|
mod user;
|
|
|
mod user;
|
|
|
|
|
|
|
|
|
use config::Config;
|
|
|
|
|
|
|
|
|
use config::{Config, TomlConfig};
|
|
|
use context::{ContextBundle, ContextOptions};
|
|
|
use context::{ContextBundle, ContextOptions};
|
|
|
use dispatcher::Dispatcher;
|
|
|
use dispatcher::Dispatcher;
|
|
|
|
|
|
|
|
|
fn old_main() {
|
|
|
|
|
|
|
|
|
fn old_main(config: Config) {
|
|
|
let (request_tx, _request_rx) = crossbeam_channel::bounded(100);
|
|
|
let (request_tx, _request_rx) = crossbeam_channel::bounded(100);
|
|
|
let (_response_tx, response_rx) = crossbeam_channel::bounded(100);
|
|
|
let (_response_tx, response_rx) = crossbeam_channel::bounded(100);
|
|
|
|
|
|
|
|
|
let mut client =
|
|
|
|
|
|
client::Client::new(request_tx, response_rx, Config::default());
|
|
|
|
|
|
|
|
|
let mut client = client::Client::new(request_tx, response_rx, config);
|
|
|
|
|
|
|
|
|
client.run();
|
|
|
client.run();
|
|
|
}
|
|
|
}
|
|
|
@ -77,9 +78,7 @@ async fn run_client( |
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn async_main() -> anyhow::Result<()> {
|
|
|
|
|
|
let config = Config::default();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn async_main(config: Config) -> anyhow::Result<()> {
|
|
|
let mut options = ContextOptions::default();
|
|
|
let mut options = ContextOptions::default();
|
|
|
options.initial_state.user_name = config.credentials.user_name().to_string();
|
|
|
options.initial_state.user_name = config.credentials.user_name().to_string();
|
|
|
|
|
|
|
|
|
@ -142,15 +141,29 @@ async fn main() -> anyhow::Result<()> { |
|
|
.long("sync")
|
|
|
.long("sync")
|
|
|
.help("Use the old synchronous engine."),
|
|
|
.help("Use the old synchronous engine."),
|
|
|
)
|
|
|
)
|
|
|
|
|
|
.arg(
|
|
|
|
|
|
Arg::with_name("config")
|
|
|
|
|
|
.short("c")
|
|
|
|
|
|
.long("config")
|
|
|
|
|
|
.value_name("FILE")
|
|
|
|
|
|
.required(true)
|
|
|
|
|
|
.help("Path to the config file to use."),
|
|
|
|
|
|
)
|
|
|
.get_matches();
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
|
|
|
|
let path = Path::new(matches.value_of("config").unwrap());
|
|
|
|
|
|
let toml_config = TomlConfig::from_file_path(path).await?;
|
|
|
|
|
|
let config = Config::from_toml(toml_config)?;
|
|
|
|
|
|
|
|
|
if matches.is_present("sync") {
|
|
|
if matches.is_present("sync") {
|
|
|
info!("Running in synchronous mode.");
|
|
|
info!("Running in synchronous mode.");
|
|
|
tokio::task::spawn_blocking(old_main)
|
|
|
|
|
|
|
|
|
tokio::task::spawn_blocking(|| old_main(config))
|
|
|
.await
|
|
|
.await
|
|
|
.context("running synchronous main")
|
|
|
.context("running synchronous main")
|
|
|
} else {
|
|
|
} else {
|
|
|
info!("Running in asynchronous mode.");
|
|
|
info!("Running in asynchronous mode.");
|
|
|
async_main().await.context("running asynchronous main")
|
|
|
|
|
|
|
|
|
async_main(config)
|
|
|
|
|
|
.await
|
|
|
|
|
|
.context("running asynchronous main")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|