use std::io::Write;
use super::cli::HintsArgs;
use super::dispatch::EXIT_OK;
use super::host::Host;
use crate::discover::{Hints, RunRecord, hints_path};
use crate::exec::{CargoOptions, gamma_base};
use crate::report::{Styler, quantity};
pub(super) fn hints_with_cargo<H: Host>(host: &mut H, args: &HintsArgs, styler: Styler, cargo: &CargoOptions) -> crate::Result<i32> {
let selection = args.select.selection()?;
let plan = crate::discover::plan_for_build(&args.select, &selection, None, cargo, &mut |_| {})?;
let base = gamma_base(&plan.root, args.cache_dir.as_deref());
let record = RunRecord::load(&base);
let promoted = Hints::promoted(&record, &plan.mutants);
if promoted.is_empty() {
writeln!(
host.error(),
"{} nothing to promote: no run under `{base}` has recorded a killing test or an unviable mutant for the current population",
styler.verb("Finished")
)?;
return Ok(EXIT_OK);
}
let path = hints_path(&plan.root);
if args.dry_run {
let counts = promoted.counts();
writeln!(
host.error(),
"{} `{path}` would carry {} and {}, for {}",
styler.verb("Preview"),
quantity(counts.probes, "killing test"),
quantity(counts.ordering, "build-order hint"),
quantity(counts.mutants, "mutant")
)?;
return Ok(EXIT_OK);
}
let promotion = promoted.write(&path)?;
let verb = if promotion.changed { "Wrote" } else { "Unchanged" };
writeln!(
host.error(),
"{} `{path}`: {} and {}, for {}",
styler.verb(verb),
quantity(promotion.probes, "killing test"),
quantity(promotion.ordering, "build-order hint"),
quantity(promotion.mutants, "mutant")
)?;
Ok(EXIT_OK)
}