"memchr",
]
-[[package]]
-name = "ansi_term"
-version = "0.12.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
-dependencies = [
- "winapi",
-]
-
[[package]]
name = "anyhow"
version = "1.0.52"
[[package]]
name = "clap"
-version = "2.34.0"
+version = "3.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
+checksum = "f6f34b09b9ee8c7c7b400fe2f8df39cafc9538b03d6ba7f4ae13e4cb90bfbb7d"
dependencies = [
- "ansi_term",
"atty",
"bitflags",
+ "clap_derive",
+ "indexmap",
+ "lazy_static",
+ "os_str_bytes",
"strsim",
+ "termcolor",
"textwrap",
- "unicode-width",
- "vec_map",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41a0645a430ec9136d2d701e54a95d557de12649a9dd7109ced3187e648ac824"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
]
[[package]]
"web-sys",
]
+[[package]]
+name = "hashbrown"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
+
+[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
[[package]]
name = "hermit-abi"
version = "0.1.19"
"unicode-normalization",
]
+[[package]]
+name = "indexmap"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
+dependencies = [
+ "autocfg",
+ "hashbrown",
+]
+
[[package]]
name = "infer"
version = "0.2.3"
"vcpkg",
]
+[[package]]
+name = "os_str_bytes"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
[[package]]
name = "strsim"
-version = "0.8.0"
+version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
[[package]]
name = "textwrap"
-version = "0.11.0"
+version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
-dependencies = [
- "unicode-width",
-]
+checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
[[package]]
name = "thiserror"
"tinyvec",
]
-[[package]]
-name = "unicode-width"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
-
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
-[[package]]
-name = "vec_map"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
-
[[package]]
name = "version_check"
version = "0.9.4"
use std::env::set_current_dir;
use std::fs::read_to_string;
use std::future::Future;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::time::Duration;
-use clap::{app_from_crate, crate_authors, crate_description, crate_name, crate_version, AppSettings, Arg, SubCommand};
+use clap::{Parser, Subcommand};
use futures::{channel::mpsc::channel, future::pending, select, FutureExt, StreamExt};
use redis::{Client, RedisError};
use signal_hook::consts::signal::*;
Ok(response)
}
+#[derive(Parser)]
+#[clap(version, author, about)]
+struct Args {
+ #[clap(short = 'c', long = "config")]
+ config: Option<PathBuf>,
+ #[clap(subcommand)]
+ command: Option<Command>,
+}
+
+#[derive(Subcommand)]
+enum Command {
+ /// Serve the website, websocket connections and start a dealer for each game (default)
+ All,
+ /// Serve the website and websocket connections
+ Server,
+ /// Start a dealer for each game
+ Dealer {
+ /// Partition all games into M groups and run dealer N of M
+ #[clap(default_value_t)]
+ partition: Partition,
+ },
+}
+
+impl Default for Command {
+ fn default() -> Self {
+ Command::All
+ }
+}
+
#[async_std::main]
async fn main() -> Result<(), tide::Error> {
- let matches = app_from_crate!()
- .arg(
- Arg::with_name("config")
- .short("c")
- .long("config")
- .value_name("FILE")
- .takes_value(true)
- .global(true)
- .help("Path to configuration file in TOML format"),
- )
- .setting(AppSettings::VersionlessSubcommands)
- .subcommand(SubCommand::with_name("server").about("Serve the website and websocket connections"))
- .subcommand(
- SubCommand::with_name("dealer").about("Start a dealer for each game").arg(
- Arg::with_name("partition")
- .value_name("N/M")
- .default_value("1/1")
- .validator(|partition| partition.parse::<Partition>().map(drop))
- .help("Partition all games into M groups and run dealer N of M"),
- ),
- )
- .subcommand(SubCommand::with_name("all").about("Serve the website, websocket connections and start a dealer for each game (default)"))
- .get_matches();
-
- let config = match matches.value_of_os("config") {
+ let args = Args::parse();
+
+ let config = match args.config {
Some(path) => {
- let config = toml::from_str(&read_to_string(path)?)?;
+ let config = toml::from_str(&read_to_string(&path)?)?;
if let Some(dir) = Path::parent(path.as_ref()) {
if !dir.as_os_str().is_empty() {
set_current_dir(dir)?;
.format_timestamp_millis()
.init();
- let mut run_server = true;
- let mut run_dealer = true;
- let mut partition = Partition::default();
+ let (run_server, run_dealer, partition);
- match matches.subcommand() {
- ("server", _) => run_dealer = false,
- ("dealer", Some(args)) => {
+ match args.command {
+ None | Some(Command::All) => {
+ run_server = true;
+ run_dealer = true;
+ partition = Partition::default();
+ }
+ Some(Command::Server) => {
+ run_server = true;
+ run_dealer = false;
+ partition = Partition::default();
+ }
+ Some(Command::Dealer { partition: part}) => {
run_server = false;
- partition = args.value_of("partition").unwrap().parse().unwrap();
+ run_dealer = true;
+ partition = part;
}
- _ => {}
}
-
+
let mut first_attempt = true;
loop {