summaryrefslogtreecommitdiff
path: root/src
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 /src
parent2183539b5917994bdee36fdb50357a5eb891453b (diff)
Support command-line parameters.
- `--help`: print help menu. - `--config`: specify which config file to use. - `--version`: print version and exit.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs15
1 files changed, 13 insertions, 2 deletions
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) {