mirror of
https://github.com/lov3b/ecb-rates.git
synced 2025-12-14 08:30:08 +01:00
Add order by option
This commit is contained in:
19
src/cli.rs
19
src/cli.rs
@@ -29,11 +29,21 @@ pub struct Cli {
|
||||
#[arg(long = "force-color")]
|
||||
pub force_color: bool,
|
||||
|
||||
/// Sort by the currency name (in alphabetical order), or by the rate value (low -> high)
|
||||
#[arg(value_enum, long = "sort-by", short = 's', default_value_t = SortBy::Currency)]
|
||||
pub sort_by: SortBy,
|
||||
|
||||
/// 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 SortBy {
|
||||
Currency,
|
||||
Rate,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||
pub enum Resolution {
|
||||
TODAY,
|
||||
@@ -51,6 +61,15 @@ impl Resolution {
|
||||
}
|
||||
}
|
||||
|
||||
impl SortBy {
|
||||
pub fn get_comparer(&self) -> fn(&(&str, f64), &(&str, f64)) -> std::cmp::Ordering {
|
||||
match self {
|
||||
Self::Currency => |a, b| a.0.cmp(&b.0),
|
||||
Self::Rate => |a, b| a.1.total_cmp(&b.1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||
pub enum FormatOption {
|
||||
/// JSON output
|
||||
|
||||
Reference in New Issue
Block a user