diff options
| author | tv <tv@krebsco.de> | 2026-12-01 05:13:36 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 05:13:36 +0000 |
| commit | 60da3a663ed070c1e6c5d2a1b171e316a0395bbd (patch) | |
| tree | c11fcce3cb5480413dce3d1aefa7d05b681b3df6 /src/main.rs | |
| parent | cd06c0a8ed52e9c251a5f2c0debb6f263ce74705 (diff) | |
enstate: --pack --dry-run, every problem of a source list
Reads every source and writes nothing: every problem, not just the
first, by address, with kind, location and variables, and the source,
as text or JSON (--json): an item the schema has no slot for, a record
in a type without records, a required slot without an item, a location
that doesn't exist, a source that can't be read (with what it said), a
record that isn't JSON. Exit status 1 if there are problems. --pack
itself refuses with the same list; --out isn't for a dry run, --json
only for one. The completion offers accordingly.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs index 2df4c78..ca7d0df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,13 +147,13 @@ fn command() -> Command { Arg::new("json") .long("json") .action(ArgAction::SetTrue) - .help("Print JSON (--plan, --apply, --stage, --status, --materialize, --migrate)"), + .help("Print JSON (--plan, --apply, --stage, --status, --materialize, --migrate, --pack --dry-run)"), ) .arg( Arg::new("dry-run") .long("dry-run") .action(ArgAction::SetTrue) - .help("With --migrate: say what it would do, changing nothing"), + .help("With --migrate, --pack: say what it would do, or what keeps it from it, changing nothing"), ) .arg( Arg::new("out") @@ -229,11 +229,12 @@ fn run() -> Result<ExitCode> { if out.is_some() && command != "pack" { bail!("--out is for --pack only"); } - if matches.get_flag("dry-run") && command != "migrate" { - bail!("--dry-run is for --migrate only"); + let dry_run = matches.get_flag("dry-run"); + if dry_run && !matches!(command, "migrate" | "pack") { + bail!("--dry-run is for --migrate and --pack only"); } - if json && command == "pack" { - bail!("--json is not for --pack"); + if json && command == "pack" && !dry_run { + bail!("--json is for --pack only with --dry-run"); } // A setting given as an argument that the command doesn't use is an error; from a // configuration file, which holds them for every command, it isn't. @@ -245,9 +246,26 @@ fn run() -> Result<ExitCode> { } } if command == "pack" { - let out = out.context("--pack needs --out DIR")?; let schema = settings.schema.as_deref().map(Schema::load).transpose()?; - for warning in enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())? { + let path = path.as_deref().unwrap(); + if dry_run { + if out.is_some() { + bail!("--out is not for a dry run"); + } + let report = enstate::pack::dry_run(path, schema.as_ref())?; + if json { + println!("{}", serde_json::to_string_pretty(&report)?); + } else { + print_report(&report)?; + } + return Ok(if report.problems.is_empty() { + ExitCode::SUCCESS + } else { + ExitCode::from(1) + }); + } + let out = out.context("--pack needs --out DIR, or --dry-run")?; + for warning in enstate::pack::pack(path, &out, schema.as_ref())? { eprintln!("enstate: warning: {warning}"); } return Ok(ExitCode::SUCCESS); @@ -321,13 +339,8 @@ fn run() -> Result<ExitCode> { Ok(ExitCode::SUCCESS) } "migrate" => { - let migration = enstate::migrate::migrate( - &schema, - &schema_bytes, - &store, - matches.get_flag("dry-run"), - &systemctl, - )?; + let migration = + enstate::migrate::migrate(&schema, &schema_bytes, &store, dry_run, &systemctl)?; if json { println!("{}", serde_json::to_string_pretty(&migration)?); } else { @@ -662,3 +675,25 @@ fn uses(command: &str, setting: &str) -> bool { _ => true, } } + +fn print_report(report: &enstate::pack::Report) -> Result<()> { + let style = Style::new(); + let mut out = std::io::stdout().lock(); + for warning in &report.warnings { + writeln!(out, "{} {warning}", style.paint("33", "warning:"))?; + } + for problem in &report.problems { + writeln!(out, "{problem}")?; + } + let verdict = if report.problems.is_empty() { + style.paint("32", "nothing missing") + } else { + style.paint("31", &format!("{} problems", report.problems.len())) + }; + writeln!( + out, + "channel {}: {} items, {verdict}", + report.channel, report.items + )?; + Ok(()) +} |
