summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-03-30 22:28:17 +0800
committerKeuin <[email protected]>2022-03-30 22:28:17 +0800
commita1c60b95e831de65339151f47b4bae6fd43bce41 (patch)
treef4bb0bd6c073021e8e042a141bfb55a01559aafa
parent2183539b5917994bdee36fdb50357a5eb891453b (diff)
Support command-line parameters.
- `--help`: print help menu. - `--config`: specify which config file to use. - `--version`: print version and exit.
-rw-r--r--Cargo.lock75
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs15
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
@@ -62,6 +62,17 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -160,6 +171,36 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -832,6 +873,7 @@ name = "kimikuri_rs"
version = "0.5.1"
dependencies = [
"bs58",
+ "clap",
"futures",
"serde",
"serde_derive",
@@ -1113,6 +1155,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1865,6 +1916,21 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2400,6 +2466,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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<T: Clone + Send>(obj: T) -> impl Filter<Extract=(T, ), Error=Infa
warp::any().map(move || obj.clone())
}
+#[derive(Parser, Debug)]
+#[clap(author, version, about, long_about = None)]
+struct CliArgs {
+ /// The configuration file to use.
+ #[clap(short, long, default_value_t = String::from(CONFIG_FILE_NAME))]
+ config: String,
+}
+
#[instrument]
#[tokio::main]
async fn main() {
- eprintln!("Loading configuration file {}...", CONFIG_FILE_NAME);
- let config = Config::from_file(CONFIG_FILE_NAME);
+ let args = CliArgs::parse();
+
+ eprintln!("Loading configuration file {}...", args.config);
+ let config = Config::from_file(args.config.as_str());
// configure logger
let log_level = match Level::from_str(&*config.log_level) {