1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use clap::{Args, Parser, Subcommand};
/// Cli styles
pub fn get_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.usage(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))),
)
.header(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))),
)
.literal(
anstyle::Style::new()
.bold()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))),
)
.invalid(
anstyle::Style::new()
.bold()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))),
)
.error(
anstyle::Style::new()
.bold()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))),
)
.valid(
anstyle::Style::new()
.bold()
.underline()
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))),
)
.placeholder(
anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::White))),
)
}
#[derive(Parser)]
#[command(name = "rustance")]
#[command(version = "0.2")]
#[command(about = "Calculate Your Balances.", long_about = None)]
#[command(styles=get_styles())]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// List all the Wallet Balances.
ListAll(ListAllArgs),
/// Add the new income.
Income(AmountArgs),
/// Add the new outcome.
Outcome(AmountArgs),
/// patch record.
PatchRecord(PatchRecordArgs),
/// delete record.
DeleteRecord(DeleteRecordArgs),
}
#[derive(Args)]
pub struct ListAllArgs {
// /// List all the Wallet Balances.
// /// It will print the verbose information if the verbose is true.
// ///
// /// The default output is a table of money and month statistics.
// /// The verbose output will list all the addtional msg.
// #[arg(short, long, default_value_t = false)]
// pub verbose: bool,
/// Time select.
#[arg(short, long)]
pub time: Option<String>,
}
#[derive(Args)]
pub struct AmountArgs {
/// the amount of money. e.g. 100.00.
/// The amount must be greater than 0.
/// and the digit after the decimal point must be less than 2.
pub amount: f32,
/// add if some additional message is needed.
pub add_msg: Option<String>,
}
#[derive(Args)]
pub struct DeleteRecordArgs {
/// the id of the record.
/// will show the id of the record before delete.
pub id: i32,
}
#[derive(Args)]
pub struct PatchRecordArgs {
/// the id of the record.
pub id: i32,
/// the amount of money. e.g. 100.00.
/// The amount must be greater than 0.
/// and the digit after the decimal point must be less than 2.
#[arg(long)]
pub amount: Option<f32>,
/// the in or out of the record.
/// true means income, false means outcome.
#[arg(short, long)]
pub in_or_out: Option<bool>,
/// add if some additional message is needed.
#[arg(short, long)]
pub add_msg: Option<String>,
}