From 6074db176a48329b73bd88b49092062f0a1d54e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 21 May 2023 23:40:54 +0200 Subject: [PATCH] Add argument parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- Cargo.toml | 1 + src/main.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dafcb44..4713035 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Maxime “pep” Buquet "] license = "AGPL-3.0+" [dependencies] +clap = { version = "4.3", features = [ "cargo", "derive" ] } gitlab = "0.1511.0" hyper = { version = "0.14", features = [ "full" ] } log = "0.4" diff --git a/src/main.rs b/src/main.rs index 356d5e5..090d279 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,16 +28,32 @@ use std::convert::Infallible; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; +use clap::Parser; use hyper::{ service::{make_service_fn, service_fn}, Server, }; use tokio::sync::mpsc; +use xmpp_parsers::BareJid; + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Account address + #[arg(short, long)] + jid: BareJid, + + /// Account password + #[arg(short, long)] + password: String, +} #[tokio::main] async fn main() { pretty_env_logger::init(); + let args = Args::parse(); + let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let (value_tx, mut value_rx) = mpsc::unbounded_channel::(); let value_tx = Arc::new(Mutex::new(value_tx)); @@ -54,7 +70,7 @@ async fn main() { println!("Listening on http://{}", addr); let _join = tokio::spawn(server); - let mut client = XmppClient::new("JID", "PASSWD"); + let mut client = XmppClient::new(&String::from(args.jid), args.password.as_str()); loop { tokio::select! {