ecb-rates/src/cli.rs

61 lines
1.5 KiB
Rust
Raw Normal View History

2025-01-04 18:18:38 +01:00
use clap::{arg, Parser, ValueEnum};
use crate::ecb_url;
2025-01-04 17:01:42 +01:00
#[derive(Debug, Parser)]
#[command(author, version, about)]
pub struct Cli {
/// Which currencies do you want to fetch rates for?
#[arg(long = "currencies", short = 'c')]
pub currencies: Vec<String>,
2025-01-04 18:18:38 +01:00
#[arg(value_enum, default_value_t = FormatOption::Plain)]
pub command: FormatOption,
/// Show the time in the output
2025-01-04 20:45:30 +01:00
#[arg(long = "display-time", default_value_t = true)]
2025-01-04 18:18:38 +01:00
pub display_time: bool,
/// Print currencies in a compact single line
#[arg(long = "compact")]
pub compact: bool,
2025-01-07 15:52:01 +01:00
/// Override the cache
#[arg(long = "no-cache")]
pub no_cache: bool,
2025-01-08 13:52:30 +01:00
/// Force color in output. Normally it will disable color in pipes
#[arg(long = "force-color")]
pub force_color: bool,
2025-01-04 18:18:38 +01:00
/// Amount of data
#[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')]
pub resolution: Resolution,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Resolution {
TODAY,
HistDays90,
HistDay,
}
impl Resolution {
pub fn to_ecb_url(&self) -> &'static str {
match self {
Resolution::TODAY => ecb_url::TODAY,
Resolution::HistDays90 => ecb_url::hist::DAYS_90,
Resolution::HistDay => ecb_url::hist::DAILY,
}
}
2025-01-04 17:01:42 +01:00
}
2025-01-04 18:18:38 +01:00
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum FormatOption {
/// JSON output
Json,
2025-01-04 17:01:42 +01:00
/// Plain line-by-line output (with extra flags)
2025-01-04 18:18:38 +01:00
Plain,
2025-01-04 17:01:42 +01:00
}