Core is done

This commit is contained in:
2025-01-04 18:18:38 +01:00
parent b9843d65a1
commit 272c5d15c8
4 changed files with 150 additions and 29 deletions

View File

@@ -1,4 +1,6 @@
use clap::{arg, Parser, Subcommand};
use clap::{arg, Parser, ValueEnum};
use crate::ecb_url;
#[derive(Debug, Parser)]
#[command(author, version, about)]
@@ -7,25 +9,44 @@ pub struct Cli {
/// Which currencies do you want to fetch rates for?
#[arg(long = "currencies", short = 'c')]
pub currencies: Vec<String>,
/// Which subcommand (output format) we are using
#[command(subcommand)]
pub command: FormatCommand,
#[arg(value_enum, default_value_t = FormatOption::Plain)]
pub command: FormatOption,
/// Show the time in the output
#[arg(long = "display-time")]
pub display_time: bool,
/// Print currencies in a compact single line
#[arg(long = "compact")]
pub compact: bool,
/// Amount of data
#[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')]
pub resolution: Resolution,
}
/// Subcommand enum for output format
#[derive(Debug, Subcommand)]
pub enum FormatCommand {
/// Minimal JSON output
JSONMin,
/// Pretty-printed JSON output
JSONPretty,
/// Plain line-by-line output (with extra flags)
Plain {
/// Show the time in the output
#[arg(long = "display-time")]
display_time: bool,
/// Print currencies in a compact single line
#[arg(long = "compact")]
compact: bool,
},
#[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,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum FormatOption {
/// JSON output
Json,
/// Plain line-by-line output (with extra flags)
Plain,
}