Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flags #12

Merged
merged 6 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- changed
- removed

### v0.4.2 (2024-05-03)

- changed
- Fix flags

### v0.4.1 (2024-04-06)

- added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pigeon-rs"
version = "0.4.1"
version = "0.4.2"
authors = ["quambene <[email protected]>"]
description = "Command line tool for cheap and efficient email automation"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -23,11 +23,11 @@ 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);
}

if matches.contains_id(arg::SAVE) {
if matches.get_flag(arg::SAVE) {
let save_dir = Path::new(arg::value(arg::SAVE_DIR, matches)?);

// If argument 'FILE_TYPE' is not present the default value 'csv' will be used
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions src/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?);
Expand All @@ -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);
}

Expand All @@ -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();

Expand All @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/send_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -44,15 +44,15 @@ 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);
}

if dry_run {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/simple_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/email_builder/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/email_builder/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/email_provider/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
)?;
Expand Down
2 changes: 1 addition & 1 deletion src/email_transmission/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Client<'a> {
}

pub fn from_args(matches: &ArgMatches) -> Result<Self, anyhow::Error> {
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)));
}
Expand Down
Loading