refactor clap into a separate file

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
Charles Hall 2024-03-12 22:20:03 -04:00 committed by June
parent 5454b653fe
commit 3160a36634
4 changed files with 20 additions and 13 deletions

15
src/clap.rs Normal file
View file

@ -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<String>,
}
/// Parse commandline arguments into structured data
pub fn parse() -> Args { Args::parse() }

View file

@ -1,4 +1,5 @@
pub mod api;
pub mod clap;
mod config;
mod database;
mod service;

View file

@ -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<String>,
}
#[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() {

View file

@ -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,