From 3160a366341c7f6fe01ef470d09e49301de8cc21 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 12 Mar 2024 22:20:03 -0400 Subject: [PATCH] refactor clap into a separate file Signed-off-by: strawberry --- src/clap.rs | 15 +++++++++++++++ src/lib.rs | 1 + src/main.rs | 11 +---------- src/service/admin/mod.rs | 6 +++--- 4 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 src/clap.rs diff --git a/src/clap.rs b/src/clap.rs new file mode 100644 index 00000000..dc3655a8 --- /dev/null +++ b/src/clap.rs @@ -0,0 +1,15 @@ +//! Integration with `clap` + +use clap::Parser; + +/// Commandline arguments +#[derive(Parser, Debug)] +#[clap(version, about, long_about = None)] +pub struct Args { + #[arg(short, long)] + /// Optional argument to the path of a conduwuit config TOML file + pub config: Option, +} + +/// Parse commandline arguments into structured data +pub fn parse() -> Args { Args::parse() } diff --git a/src/lib.rs b/src/lib.rs index 39a09141..4ff91f56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod api; +pub mod clap; mod config; mod database; mod service; diff --git a/src/main.rs b/src/main.rs index 479c491b..d027f4b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ use axum::{ use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; #[cfg(feature = "axum_dual_protocol")] use axum_server_dual_protocol::ServerExt; -use clap::Parser; use conduit::api::{client_server, server_server}; pub use conduit::*; // Re-export everything from the library crate use either::Either::{Left, Right}; @@ -56,17 +55,9 @@ use tracing_subscriber::{prelude::*, EnvFilter}; #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; -#[derive(Parser, Debug)] -#[clap(version, about, long_about = None)] -struct Args { - #[arg(short, long)] - /// Optional argument to the path of a conduwuit config TOML file - config: Option, -} - #[tokio::main] async fn main() { - let args = Args::parse(); + let args = clap::parse(); // Initialize config let raw_config = if Env::var("CONDUIT_CONFIG").is_some() { diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 704e2466..f8739a4b 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -20,14 +20,14 @@ use ruma::{ }, TimelineEventType, }, - CanonicalJsonObject, CanonicalJsonValue, EventId, MxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, - RoomId, RoomOrAliasId, RoomVersionId, ServerName, UserId, + CanonicalJsonObject, EventId, MxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, + RoomOrAliasId, RoomVersionId, ServerName, UserId, }; use serde_json::value::to_raw_value; use tokio::sync::{mpsc, Mutex, RwLock}; use tracing::{debug, error, info, warn}; -use super::pdu::{self, PduBuilder}; +use super::pdu::PduBuilder; use crate::{ api::client_server::{get_alias_helper, leave_all_rooms, leave_room, AUTO_GEN_PASSWORD_LENGTH}, services,