Add check option

This commit is contained in:
carbotaniuman 2022-05-02 14:05:12 -05:00 committed by Josh Holmer
parent 7ffbe1fb78
commit 9054b2d947
2 changed files with 18 additions and 0 deletions

View file

@ -131,6 +131,10 @@ pub struct Options {
///
/// Default: `false`
pub fix_errors: bool,
/// Don't actually run any optimizations, just parse the PNG file.
///
/// Default: `false`
pub check: bool,
/// Don't actually write any output, just calculate the best results.
///
/// Default: `false`
@ -299,6 +303,7 @@ impl Default for Options {
Options {
backup: false,
check: false,
pretend: false,
fix_errors: false,
force: false,
@ -363,6 +368,11 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<(
let mut png = PngData::from_slice(&in_data, opts.fix_errors)?;
if opts.check {
info!("Running in check mode, not optimizing");
return Ok(());
}
// Run the optimizer on the decoded PNG.
let mut optimized_output = optimize_png(&mut png, &in_data, opts, deadline)?;

View file

@ -83,6 +83,10 @@ fn main() {
.help("Preserve file attributes if possible")
.short('p')
.long("preserve"))
.arg(Arg::new("check")
.help("Do not run any optimization passes")
.short('c')
.long("check"))
.arg(Arg::new("pretend")
.help("Do not write any files, only calculate compression gains")
.short('P')
@ -415,6 +419,10 @@ fn parse_opts_into_struct(
opts.fix_errors = true;
}
if matches.is_present("check") {
opts.check = true;
}
if matches.is_present("pretend") {
opts.pretend = true;
}