src: main: Implement commandline arguments parsing
Use clap for argument parsing, read the config file path from the commandline and implement basic help and version options
This commit is contained in:
3 files changed
+142
-1
No files matched your search
+14
-1
@@ -35,6 +35,17 @@ use crate::{
|
||||
use std::sync::{ Arc, Mutex };
|
||||
use tracing::{ info, debug };
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
/// Matrix bot posting when the front door is opened or closed
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Configuration file path
|
||||
#[arg(short, long, default_value_t = "config.yml".into())]
|
||||
config: String,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum LolOpenerStatus {
|
||||
Open,
|
||||
@@ -45,7 +56,9 @@ enum LolOpenerStatus {
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let config = Config::load("config.yml").unwrap_or_else(|e| {
|
||||
let args = Args::parse();
|
||||
|
||||
let config = Config::load(&args.config).unwrap_or_else(|e| {
|
||||
panic!("Failed to load config: {e:?}")
|
||||
});
|
||||
let config = Arc::new(config);
|
||||
|
||||
Reference in new issue
Block a user