feat: 用 Rust 重写打卡记录,命令行输出最近一周

This commit is contained in:
2026-11-19 11:40:42 +08:00
parent 387eaf4df5
commit b948f7a5d3
33 changed files with 2791 additions and 1690 deletions
+14
View File
@@ -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" }
+39
View File
@@ -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(())
}