invert option

This commit is contained in:
Love 2025-01-09 12:21:10 +01:00
parent 4445685444
commit d842fb786c
2 changed files with 9 additions and 1 deletions

View File

@ -37,6 +37,10 @@ pub struct Cli {
#[arg(long = "perspective", short = 'p')] #[arg(long = "perspective", short = 'p')]
pub perspective: Option<String>, pub perspective: Option<String>,
/// Invert the rate
#[arg(long = "invert", short = 'i')]
pub should_invert: bool,
/// Amount of data /// Amount of data
#[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')] #[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')]
pub resolution: Resolution, pub resolution: Resolution,

View File

@ -7,7 +7,7 @@ use ecb_rates::cli::{Cli, FormatOption};
use ecb_rates::models::ExchangeRateResult; use ecb_rates::models::ExchangeRateResult;
use ecb_rates::parsing::parse; use ecb_rates::parsing::parse;
use ecb_rates::table::{TableRef, TableTrait as _}; 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<Vec<ExchangeRateResult>> { async fn get_and_parse(url: impl IntoUrl) -> anyhow::Result<Vec<ExchangeRateResult>> {
let client = Client::new(); 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() { if !cli.currencies.is_empty() {
let currencies = cli let currencies = cli
.currencies .currencies