From a81c0e631cf5d678acfb06e364ac0de073ea9d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 27 May 2023 17:37:28 +0200 Subject: [PATCH] Stop using clap's 'derive' feature for a single argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- Cargo.toml | 2 +- src/main.rs | 28 ++++++++++++++++------------ src/xmpp.rs | 3 +++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 07990d4..0cc4383 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Maxime “pep” Buquet "] license = "AGPL-3.0+" [dependencies] -clap = { version = "4.3", features = [ "cargo", "derive" ] } +clap = { version = "4.3", features = [ "cargo" ] } gitlab = "0.1511.0" hyper = { version = "0.14", features = [ "full" ] } jid = { version = "*", features = [ "serde" ] } diff --git a/src/main.rs b/src/main.rs index 2c8680b..b07e72e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,23 +33,16 @@ use std::net::{IpAddr, Ipv6Addr, SocketAddr}; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; -use clap::Parser; +use clap::{command, value_parser, Arg}; use hyper::{ service::{make_service_fn, service_fn}, Server, }; +use log::debug; use serde::{Deserialize, Serialize}; use tokio::sync::mpsc; use xmpp_parsers::BareJid; -#[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -struct Args { - /// Config file path - #[arg(short, long)] - config: Option, -} - #[derive(Debug, Serialize, Deserialize)] struct Config { /// Account address @@ -100,14 +93,23 @@ fn config_from_file(file: PathBuf) -> Result { async fn main() -> Result { pretty_env_logger::init(); - let args = Args::parse(); + let matches = command!() + .arg( + Arg::new("config") + .short('c') + .long("config") + .required(false) + .value_parser(value_parser!(PathBuf)), + ) + .get_matches(); + let config = { - let path = match args.config { + let path = match matches.get_one::("config") { Some(path) => { if !path.starts_with("/") { std::env::current_dir()?.join(path) } else { - path + path.to_path_buf() } } None => { @@ -123,6 +125,8 @@ async fn main() -> Result { } }; + debug!("Using configuration file: {:?}", path); + match config_from_file(path) { Ok(config) => config, Err(err) => return Err(err), diff --git a/src/xmpp.rs b/src/xmpp.rs index 66eb00a..7972c98 100644 --- a/src/xmpp.rs +++ b/src/xmpp.rs @@ -64,6 +64,9 @@ impl XmppClient { .await } } + Event::Disconnected => { + debug!("XMPP Disconnected"); + } _ => { debug!("XMPP Event not supported") }