From d842fb786cc9723560393f57e1d36a550e12c34e Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Thu, 9 Jan 2025 12:21:10 +0100 Subject: [PATCH] invert option --- src/cli.rs | 4 ++++ src/main.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 8d33e9e..b2f4c0a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,6 +37,10 @@ pub struct Cli { #[arg(long = "perspective", short = 'p')] pub perspective: Option, + /// Invert the rate + #[arg(long = "invert", short = 'i')] + pub should_invert: bool, + /// Amount of data #[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')] pub resolution: Resolution, diff --git a/src/main.rs b/src/main.rs index b177df5..9e4d292 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use ecb_rates::cli::{Cli, FormatOption}; use ecb_rates::models::ExchangeRateResult; use ecb_rates::parsing::parse; use ecb_rates::table::{TableRef, TableTrait as _}; -use ecb_rates::utils_calc::{change_perspective, filter_currencies}; +use ecb_rates::utils_calc::{change_perspective, filter_currencies, invert_rates}; async fn get_and_parse(url: impl IntoUrl) -> anyhow::Result> { let client = Client::new(); @@ -80,6 +80,10 @@ async fn main() -> ExitCode { } } + if cli.should_invert { + invert_rates(&mut parsed); + } + if !cli.currencies.is_empty() { let currencies = cli .currencies