diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-03-06 12:56:09 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-03-06 12:56:09 +0100 |
commit | 15e573150547f956956b7c58c752e31184253fbd (patch) | |
tree | c986211e9a9b8758c85f0461b208679c28a1181b /src/main.rs | |
parent | 9079d9ec37bfd4293347539155f1164a979379be (diff) | |
download | ezau-15e573150547f956956b7c58c752e31184253fbd.tar.gz ezau-15e573150547f956956b7c58c752e31184253fbd.tar.bz2 ezau-15e573150547f956956b7c58c752e31184253fbd.zip |
put matrix & discord functionality behind gates
serenity and matrix-sdk pull in quite a lot of dependencies, which for a
minimal use of ezau might not be wanted. Therefore, we now disable those
parts by default, and the user has to opt-in into building ezau with
Discord or Matrix functionality.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index ab40d86..55bd637 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use clap::Clap; use evtclib::{Compression, Encounter, Log}; use log::{debug, error, info, warn}; @@ -20,8 +20,11 @@ mod categories; use categories::Categorizable; mod config; use config::Config; +#[cfg(feature = "im-discord")] mod discord; +#[cfg(any(feature = "im-discord", feature = "im-matrix"))] mod logbag; +#[cfg(feature = "im-matrix")] mod matrix; const DPS_REPORT_API: &str = "https://dps.report/uploadContent"; @@ -75,6 +78,8 @@ fn main() { fn inner_main(opts: &Opts) -> Result<()> { let config = config::load(&opts.config).context("Could not load configuration")?; + sanity_check(&config)?; + match &opts.subcmd { SubCommand::Watch(w) => watch(w, &config)?, SubCommand::Upload(u) => { @@ -244,3 +249,49 @@ fn upload_log(file: &Path) -> Result<String> { .json()?; Ok(resp.permalink) } + +fn sanity_check(config: &Config) -> Result<()> { + if config.discord.is_some() && !cfg!(feature = "im-discord") { + bail!( + "Discord is configured but ezau was built without Discord support. \ + Please enable the `im-discord` feature or adjust your configuration \ + to continue." + ); + } + if config.matrix.is_some() && !cfg!(feature = "im-matrix") { + bail!( + "Matrix is configured but ezau was built without Matrix support. \ + Please enable the `im-matrix` feature or adjust your configuration \ + to continue." + ); + } + Ok(()) +} + +// Dummy modules for when the features are disabled +#[cfg(not(feature = "im-discord"))] +mod discord { + use super::{Log, Result}; + use anyhow::bail; + + /// Stub, enable the `im-discord` feature to use this function. + pub fn post_link(_: &str, _: u64, _: &Log, _: &str) -> Result<()> { + bail!("Discord feature is disabled in this build!") + } +} + +#[cfg(not(feature = "im-matrix"))] +mod matrix { + use super::{Log, Result}; + use anyhow::bail; + pub struct MatrixUser; + impl From<super::config::Matrix> for MatrixUser { + fn from(_: super::config::Matrix) -> MatrixUser { + MatrixUser + } + } + /// Stub, enable the `im-matrix` feature to use this function. + pub fn post_link(_: MatrixUser, _: &str, _: &Log, _: &str) -> Result<()> { + bail!("Matrix feature is disabled in this build!") + } +} |