Stop using clap's 'derive' feature for a single argument

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-05-27 17:37:28 +02:00
parent 135a2c1611
commit a81c0e631c
3 changed files with 20 additions and 13 deletions

View file

@ -7,7 +7,7 @@ authors = ["Maxime “pep” Buquet <pep@bouah.net>"]
license = "AGPL-3.0+" license = "AGPL-3.0+"
[dependencies] [dependencies]
clap = { version = "4.3", features = [ "cargo", "derive" ] } clap = { version = "4.3", features = [ "cargo" ] }
gitlab = "0.1511.0" gitlab = "0.1511.0"
hyper = { version = "0.14", features = [ "full" ] } hyper = { version = "0.14", features = [ "full" ] }
jid = { version = "*", features = [ "serde" ] } jid = { version = "*", features = [ "serde" ] }

View file

@ -33,23 +33,16 @@ use std::net::{IpAddr, Ipv6Addr, SocketAddr};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use clap::Parser; use clap::{command, value_parser, Arg};
use hyper::{ use hyper::{
service::{make_service_fn, service_fn}, service::{make_service_fn, service_fn},
Server, Server,
}; };
use log::debug;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use xmpp_parsers::BareJid; use xmpp_parsers::BareJid;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Config file path
#[arg(short, long)]
config: Option<PathBuf>,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct Config { struct Config {
/// Account address /// Account address
@ -100,14 +93,23 @@ fn config_from_file(file: PathBuf) -> Result<Config, Error> {
async fn main() -> Result<!, Error> { async fn main() -> Result<!, Error> {
pretty_env_logger::init(); 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 config = {
let path = match args.config { let path = match matches.get_one::<PathBuf>("config") {
Some(path) => { Some(path) => {
if !path.starts_with("/") { if !path.starts_with("/") {
std::env::current_dir()?.join(path) std::env::current_dir()?.join(path)
} else { } else {
path path.to_path_buf()
} }
} }
None => { None => {
@ -123,6 +125,8 @@ async fn main() -> Result<!, Error> {
} }
}; };
debug!("Using configuration file: {:?}", path);
match config_from_file(path) { match config_from_file(path) {
Ok(config) => config, Ok(config) => config,
Err(err) => return Err(err), Err(err) => return Err(err),

View file

@ -64,6 +64,9 @@ impl XmppClient {
.await .await
} }
} }
Event::Disconnected => {
debug!("XMPP Disconnected");
}
_ => { _ => {
debug!("XMPP Event not supported") debug!("XMPP Event not supported")
} }