feat: 用 Rust 重写打卡记录,命令行输出最近一周
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "punchlog-cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "输出最近一周打卡记录"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "punchlog"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
punchlog = { path = "../punchlog" }
|
||||
@@ -0,0 +1,39 @@
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
match run() {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(err) => {
|
||||
eprintln!("{err}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> punchlog::Result<()> {
|
||||
let mut config = punchlog::AppConfig::load()?;
|
||||
let report = punchlog::load_last_week(&mut config)?;
|
||||
println!("最近一周 {} ~ {}", report.start, report.end);
|
||||
if report.days.is_empty() {
|
||||
println!("这一周没有打卡记录。");
|
||||
return Ok(());
|
||||
}
|
||||
for day in &report.days {
|
||||
let mark = if day.has_supplement { "含补" } else { " " };
|
||||
let (site, memo) = day.content();
|
||||
println!(
|
||||
"{} {} {}~{} {:.1}h {} {}",
|
||||
day.day,
|
||||
mark,
|
||||
day.first.format("%H:%M:%S"),
|
||||
day.last.format("%H:%M:%S"),
|
||||
day.hours,
|
||||
day.status.label(),
|
||||
site
|
||||
);
|
||||
if !memo.is_empty() {
|
||||
println!(" {memo}");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user