Adds dependency instead of using cli

This commit is contained in:
Dandaedre 2025-12-13 03:21:34 +01:00
parent 729a064e7d
commit a4064df89d
2 changed files with 16 additions and 9 deletions

View File

@ -6,6 +6,7 @@ resolver = "2"
[dependencies]
anyhow = "1.0.92"
badge-maker = "0.3.1"
clap = { version = "4.5.31", features = ["derive"] }
console = "0.15.11"
indicatif = "0.17.11"

View File

@ -7,6 +7,7 @@ use std::{
};
use anyhow::Context;
use badge_maker::BadgeBuilder;
use indicatif::{MultiProgress, ProgressBar};
use xshell::Shell;
@ -30,10 +31,10 @@ pub fn load_status(args: &CLIArgs) -> LastRuns {
let _ = args; // Always try to load from disk
if let Ok(mut f) = File::open(".run_status.toml") {
let mut content = String::new();
if f.read_to_string(&mut content).is_ok() {
if let Ok(deserde) = toml::from_str(&content) {
return deserde;
}
if f.read_to_string(&mut content).is_ok()
&& let Ok(deserde) = toml::from_str(&content)
{
return deserde;
}
}
LastRuns::default()
@ -181,12 +182,17 @@ pub fn write_badge(
test_name: &str,
args: &CLIArgs,
) -> Result<(), anyhow::Error> {
let output = std::process::Command::new("badge-maker")
.args(vec!["-s", "plastic", name, value, "-c", color])
.output()
.context("Running badge-maker to export the badge")?;
let svg = BadgeBuilder::new()
.label(name)
.message(value)
.color_parse(color)
.style(badge_maker::Style::Plastic)
.build()
.context("Running badge-maker to export the badge")?
.svg();
let mut f = File::create(format!("{}/{}.svg", args.output, test_name)).unwrap();
f.write_all(&output.stdout)?;
write!(f, "{}", svg).context("Writing badge")?;
Ok(())
}