From a1c60b95e831de65339151f47b4bae6fd43bce41 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 30 Mar 2022 22:28:17 +0800 Subject: Support command-line parameters. - `--help`: print help menu. - `--config`: specify which config file to use. - `--version`: print version and exit. --- Cargo.lock | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- src/main.rs | 15 +++++++++++-- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c61a8d6..d006d43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -159,6 +170,36 @@ dependencies = [ "num-traits", ] +[[package]] +name = "clap" +version = "3.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -832,6 +873,7 @@ name = "kimikuri_rs" version = "0.5.1" dependencies = [ "bs58", + "clap", "futures", "serde", "serde_derive", @@ -1112,6 +1154,15 @@ dependencies = [ "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_lot" version = "0.10.2" @@ -1864,6 +1915,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thiserror" version = "1.0.30" @@ -2399,6 +2465,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 1d54179..561c288 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,5 @@ urandom = "0.1.0" bs58 = "0.4.0" tracing = "0.1.32" tracing-subscriber = "0.3.9" -tracing-appender = "0.2.2" \ No newline at end of file +tracing-appender = "0.2.2" +clap = { version = "3.1.6", features = ["derive"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4c58eaf..34d6465 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::convert::Infallible; use std::net::{SocketAddr, ToSocketAddrs}; use std::str::FromStr; +use clap::Parser; use teloxide::prelude2::*; use tracing::{debug, info, Level}; use tracing::instrument; @@ -29,11 +30,21 @@ fn with_object(obj: T) -> impl Filter