1#![deny(missing_docs)]
20
21use std::{path::PathBuf, time::SystemTime};
22
23use radicle::git::Oid;
24
25use clap::Parser;
26use time::{macros::format_description, OffsetDateTime};
27
28pub mod report;
29pub mod run;
30pub(crate) mod runlog;
31pub mod spec;
32
33const CSS: &str = include_str!("wumpus.css");
34const STATS_TXT: &str = "stats.txt";
35const SUCCESS: &str = "SUCCESS";
36const FAILURE: &str = "FAILURE";
37
38#[derive(Debug, Parser)]
40#[clap(version)]
41pub struct Args {
42 #[clap(subcommand)]
44 pub cmd: Cmd,
45}
46
47#[derive(Debug, Parser)]
49#[allow(missing_docs)]
50pub enum Cmd {
51 Run(run::Run),
52 Report(ReportCmd),
53 DummyLog(DummyLog),
54}
55
56#[derive(Debug, Parser)]
61pub struct ReportCmd {
62 stats: PathBuf,
63 spec: PathBuf,
64 git: PathBuf,
65}
66
67impl ReportCmd {
68 pub fn run(&self) -> anyhow::Result<()> {
70 let spec = spec::Spec::from_file(&self.spec)?;
71 let report = report::Report::new(&spec.description, &self.stats)?;
72 print!("{}", report.as_html(&spec, &self.git));
73 Ok(())
74 }
75}
76
77pub(crate) fn timestamp(when: &SystemTime) -> String {
78 let fmt = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z");
79 OffsetDateTime::from(*when).format(fmt).ok().unwrap()
80}
81
82#[derive(Debug, Parser)]
87pub struct DummyLog {}
88
89impl DummyLog {
90 pub fn run(&self) {
92 let mut run_log = runlog::RunLog::default();
93 run_log.url("https://liw.fi");
94 run_log.git_ref("master");
95 run_log.git_commit(Oid::try_from("06f52d8a538e79b09bd8252a1346542ed179cd60").unwrap());
96 run_log.runcmd(
97 &["git", "clean", "-fdx"],
98 0,
99 "This is stdout",
100 "This is stderr",
101 );
102 println!("{}", run_log.as_html());
103 }
104}