From f392b37339a29ae8dc70403bc3755e04712c23ce Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:23:29 +0100 Subject: [PATCH] Add cli flag `--no-https-verification` Throws error when the flag is enabled and the eponymous feature is disabled. Currently not linked to any underlying functionality. --- src/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 406a0d3f..79307bbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ async fn main() { // Initialize logger pretty_env_logger::init(); - let matches = Command::new("Redlib") + let mut cmd = Command::new("Redlib") .version(env!("CARGO_PKG_VERSION")) .about("Private front-end for Reddit written in Rust ") .arg( @@ -158,7 +158,23 @@ async fn main() { .default_value("604800") .num_args(1), ) - .get_matches(); + .arg( + Arg::new("no-https-verification") + .long("no-https-verification") + .help("Disables HTTPS certificate verification between the instance and reddit. This can be useful to debug the HTTPS connection with an HTTPS sniffer. Only works when the 'no-https-verification' feature is enabled at compile time.") + .num_args(0), + ); + let matches = cmd.get_matches_mut(); + + #[cfg(not(feature = "no-https-verification"))] + if matches.contains_id("no-https-verification") { + cmd + .error( + clap::error::ErrorKind::InvalidValue, + "`--no-https-verification` can only be enabled if the `no-https-verification` feature is enabled", + ) + .exit() + } let address = matches.get_one::("address").unwrap(); let port = matches.get_one::("port").unwrap();