From c260fd3b753a7eb0f412b2dd9574f7368defd239 Mon Sep 17 00:00:00 2001 From: quambene Date: Thu, 2 May 2024 23:54:15 +0200 Subject: [PATCH] Fix flags --- src/cmd/connect.rs | 2 +- src/cmd/init.rs | 2 +- src/cmd/query.rs | 4 ++-- src/cmd/read.rs | 4 ++-- src/cmd/send.rs | 12 ++++++------ src/cmd/send_bulk.rs | 10 +++++----- src/cmd/simple_query.rs | 2 +- src/email_builder/message.rs | 2 +- src/email_builder/receiver.rs | 4 ++-- src/email_provider/aws.rs | 2 +- src/email_transmission/client.rs | 2 +- src/main.rs | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/cmd/connect.rs b/src/cmd/connect.rs index db0de80..6c2993a 100644 --- a/src/cmd/connect.rs +++ b/src/cmd/connect.rs @@ -8,7 +8,7 @@ use anyhow::{anyhow, Result}; use clap::ArgMatches; pub fn connect(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 0dc8656..5c60593 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -4,7 +4,7 @@ use clap::ArgMatches; use std::{env, io}; pub fn init(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } diff --git a/src/cmd/query.rs b/src/cmd/query.rs index a52c539..b21d5ff 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -8,7 +8,7 @@ use clap::ArgMatches; use std::path::Path; pub fn query(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } @@ -23,7 +23,7 @@ pub fn query(matches: &ArgMatches) -> Result<(), anyhow::Error> { let connection = DbConnection::new(&conn_vars, ssh_tunnel)?; let mut df_query = sources::query_postgres(&connection, query)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display query result: {}", df_query); } diff --git a/src/cmd/read.rs b/src/cmd/read.rs index 0713a96..a78b381 100644 --- a/src/cmd/read.rs +++ b/src/cmd/read.rs @@ -4,7 +4,7 @@ use clap::ArgMatches; use std::path::PathBuf; pub fn read(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } @@ -14,7 +14,7 @@ pub fn read(matches: &ArgMatches) -> Result<(), anyhow::Error> { let path = PathBuf::from(csv_file); let csv = sources::read_csv(&path)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display csv file: {}", csv); } diff --git a/src/cmd/send.rs b/src/cmd/send.rs index 323ebd4..04462ea 100644 --- a/src/cmd/send.rs +++ b/src/cmd/send.rs @@ -11,13 +11,13 @@ use clap::ArgMatches; use std::{io, path::Path, time::SystemTime}; pub fn send(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } let now = SystemTime::now(); - let dry_run = matches.contains_id(arg::DRY_RUN); - let is_archived = matches.contains_id(arg::ARCHIVE); + let dry_run = matches.get_flag(arg::DRY_RUN); + let is_archived = matches.get_flag(arg::ARCHIVE); let archive_dir = Path::new(arg::value(arg::ARCHIVE_DIR, matches)?); let sender = Sender(arg::value(arg::SENDER, matches)?); let receiver = Receiver(arg::value(arg::RECEIVER, matches)?); @@ -26,7 +26,7 @@ pub fn send(matches: &ArgMatches) -> Result<(), anyhow::Error> { let mime_format = MimeFormat::new(sender, receiver, &message, attachment, now)?; let email = Email::new(sender, receiver, &message, &mime_format)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display email: {:#?}", email); } @@ -40,7 +40,7 @@ pub fn send(matches: &ArgMatches) -> Result<(), anyhow::Error> { println!("Sending email to 1 receiver ..."); - if matches.contains_id(arg::ASSUME_YES) { + if matches.get_flag(arg::ASSUME_YES) { let sent_email = client.send(&email)?; sent_email.display_status(); @@ -62,7 +62,7 @@ pub fn send(matches: &ArgMatches) -> Result<(), anyhow::Error> { } } - if matches.contains_id(arg::DRY_RUN) { + if matches.get_flag(arg::DRY_RUN) { println!("Email sent (dry run)"); } else { println!("Email sent"); diff --git a/src/cmd/send_bulk.rs b/src/cmd/send_bulk.rs index 42953fd..24faeb7 100644 --- a/src/cmd/send_bulk.rs +++ b/src/cmd/send_bulk.rs @@ -11,12 +11,12 @@ use clap::ArgMatches; use std::{io, path::Path}; pub fn send_bulk(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } - let dry_run = matches.contains_id(arg::DRY_RUN); - let is_archived = matches.contains_id(arg::ARCHIVE); + let dry_run = matches.get_flag(arg::DRY_RUN); + let is_archived = matches.get_flag(arg::ARCHIVE); let archive_dir = Path::new(arg::value(arg::ARCHIVE_DIR, matches)?); let sender = Sender(arg::value(arg::SENDER, matches)?); let receivers = BulkReceiver::from_args(matches)?; @@ -44,7 +44,7 @@ pub fn send_bulk(matches: &ArgMatches) -> Result<(), anyhow::Error> { let client = Client::from_args(matches)?; let eml_formatter = EmlFormatter::new(archive_dir)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display emails: {:#?}", bulk_email); } @@ -52,7 +52,7 @@ pub fn send_bulk(matches: &ArgMatches) -> Result<(), anyhow::Error> { println!("Dry run: {}", format_green("activated")); } - if matches.contains_id(arg::ASSUME_YES) { + if matches.get_flag(arg::ASSUME_YES) { process_emails( &client, &eml_formatter, diff --git a/src/cmd/simple_query.rs b/src/cmd/simple_query.rs index 0a1b6b4..9670c31 100644 --- a/src/cmd/simple_query.rs +++ b/src/cmd/simple_query.rs @@ -4,7 +4,7 @@ use clap::ArgMatches; use postgres::{Client, NoTls, SimpleQueryMessage}; pub fn simple_query(matches: &ArgMatches) -> Result<(), anyhow::Error> { - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); } diff --git a/src/email_builder/message.rs b/src/email_builder/message.rs index 2fce0bc..a33825a 100644 --- a/src/email_builder/message.rs +++ b/src/email_builder/message.rs @@ -63,7 +63,7 @@ impl Message { let message_path = Path::new(message_file); let message = Message::read_yaml(message_path)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display message file: {:#?}", message); } diff --git a/src/email_builder/receiver.rs b/src/email_builder/receiver.rs index 0dabe68..4941555 100644 --- a/src/email_builder/receiver.rs +++ b/src/email_builder/receiver.rs @@ -46,7 +46,7 @@ impl BulkReceiver { let connection = DbConnection::new(&conn_vars, ssh_tunnel)?; let df_receiver = sources::query_postgres(&connection, query)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display query result: {}", df_receiver); } @@ -58,7 +58,7 @@ impl BulkReceiver { (None, Some(path)) => { let df_receiver = sources::read_csv(path)?; - if matches.contains_id(arg::DISPLAY) { + if matches.get_flag(arg::DISPLAY) { println!("Display csv file: {}", df_receiver); } diff --git a/src/email_provider/aws.rs b/src/email_provider/aws.rs index 6708047..e7b63e9 100644 --- a/src/email_provider/aws.rs +++ b/src/email_provider/aws.rs @@ -29,7 +29,7 @@ impl AwsSesClient { let region_name = region.name().to_string(); // Check if AWS access keys are set in environment - if matches.contains_id(arg::DRY_RUN) { + if matches.get_flag(arg::DRY_RUN) { AwsSesClient::get_credentials(&provider).context( "Missing environment variable 'AWS_ACCESS_KEY_ID' and/or 'AWS_SECRET_ACCESS_KEY'", )?; diff --git a/src/email_transmission/client.rs b/src/email_transmission/client.rs index 81cbfee..5b5bdc2 100644 --- a/src/email_transmission/client.rs +++ b/src/email_transmission/client.rs @@ -42,7 +42,7 @@ impl<'a> Client<'a> { } pub fn from_args(matches: &ArgMatches) -> Result { - if matches.contains_id(arg::DRY_RUN) { + if matches.get_flag(arg::DRY_RUN) { let client = MockClient; return Ok(Client::new(TransmissionType::Dry, Box::new(client))); } diff --git a/src/main.rs b/src/main.rs index 609f636..d0000e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ fn main() -> Result<(), anyhow::Error> { let app = app(); let matches = app.get_matches(); - if matches.contains_id(arg::VERBOSE) { + if matches.get_flag(arg::VERBOSE) { println!("matches: {:#?}", matches); }