currency_conversion_cli/
cli.rs

1//! Cli Arguments Parsing
2
3use clap::{Args, Parser, Subcommand};
4use clap_verbosity_flag::Verbosity;
5use rust_decimal::Decimal;
6
7/// Handle currency conversion using local saved conversion rates
8#[derive(Parser, Debug)]
9#[command(version, about, long_about = None)]
10pub struct CliArgs {
11    #[command(flatten)]
12    pub verbose: Verbosity,
13
14    #[command(subcommand)]
15    pub sub_command: SubCommand,
16
17    /// Optional : path to config file (default : handle by confy)
18    #[arg(long)]
19    pub config_path: Option<String>,
20
21    /// Optional : config profile name
22    #[arg(long)]
23    pub config_profile: Option<String>,
24}
25
26#[derive(Subcommand, Debug)]
27pub enum SubCommand {
28    /// Update supported symbols and conversion rates files
29    Update(UpdateArgs),
30    /// Convert a value from a currency to an other
31    Convert(ConvertArgs),
32    /// List all data from dataset indicated
33    List(ListArgs),
34    /// Show informations
35    Info(InfoArgs),
36    /// Prompt config
37    Config,
38}
39
40#[derive(Args, Debug)]
41pub struct ConvertArgs {
42    /// origin currency
43    #[arg(long)]
44    pub from: String,
45    /// destination currency
46    #[arg(long)]
47    pub to: String,
48    /// value to convert
49    pub value: Decimal,
50}
51
52#[derive(Args, Debug)]
53pub struct ListArgs {
54    /// dataset to List
55    #[command(subcommand)]
56    pub dataset: ListDataSet,
57}
58
59#[derive(Debug, Subcommand)]
60pub enum ListDataSet {
61    Symbols,
62    ConversionRates,
63}
64
65#[derive(Args, Debug)]
66pub struct InfoArgs {
67    /// show all information
68    #[arg(long, action = clap::ArgAction::SetTrue)]
69    pub all: bool,
70
71    /// show config information
72    #[arg(long, action = clap::ArgAction::SetTrue)]
73    pub config: bool,
74
75    /// show symbols information
76    #[arg(long, action = clap::ArgAction::SetTrue)]
77    pub symbols: bool,
78
79    /// show symbols information
80    #[arg(long, action = clap::ArgAction::SetTrue)]
81    pub conversion_rates: bool,
82}
83
84#[derive(Debug, Args)]
85pub struct UpdateArgs {
86    /// Update all
87    #[arg(long, action = clap::ArgAction::SetTrue)]
88    pub all: bool,
89    /// Update symbols
90    #[arg(long, action = clap::ArgAction::SetTrue)]
91    pub symbols: bool,
92    /// Update conversion rates
93    #[arg(long, action = clap::ArgAction::SetTrue)]
94    pub conversion_rates: bool,
95}