74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
extern crate clap;
|
|
|
|
use atty::Stream;
|
|
use clap::{App, Arg};
|
|
use std::path::Path;
|
|
use std::process;
|
|
use std::sync::Arc;
|
|
|
|
use crate::cache::repair::{repair, CacheRepairOptions};
|
|
use crate::commands::utils::*;
|
|
use crate::report::*;
|
|
|
|
pub fn run(args: &[std::ffi::OsString]) {
|
|
let parser = App::new("cache_repair")
|
|
.version(crate::version::tools_version())
|
|
.about("Repair binary cache metadata, and write it to a different device or file")
|
|
// flags
|
|
.arg(
|
|
Arg::with_name("ASYNC_IO")
|
|
.help("Force use of io_uring for synchronous io")
|
|
.long("async-io")
|
|
.hidden(true),
|
|
)
|
|
.arg(
|
|
Arg::with_name("QUIET")
|
|
.help("Suppress output messages, return only exit code.")
|
|
.short("q")
|
|
.long("quiet"),
|
|
)
|
|
// options
|
|
.arg(
|
|
Arg::with_name("INPUT")
|
|
.help("Specify the input device")
|
|
.short("i")
|
|
.long("input")
|
|
.value_name("FILE")
|
|
.required(true),
|
|
)
|
|
.arg(
|
|
Arg::with_name("OUTPUT")
|
|
.help("Specify the output device")
|
|
.short("o")
|
|
.long("output")
|
|
.value_name("FILE")
|
|
.required(true),
|
|
);
|
|
|
|
let matches = parser.get_matches_from(args);
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
|
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
|
|
|
let report = if matches.is_present("QUIET") {
|
|
std::sync::Arc::new(mk_quiet_report())
|
|
} else if atty::is(Stream::Stdout) {
|
|
std::sync::Arc::new(mk_progress_bar_report())
|
|
} else {
|
|
Arc::new(mk_simple_report())
|
|
};
|
|
|
|
check_input_file(input_file, &report);
|
|
|
|
let opts = CacheRepairOptions {
|
|
input: input_file,
|
|
output: output_file,
|
|
async_io: matches.is_present("ASYNC_IO"),
|
|
report: report.clone(),
|
|
};
|
|
|
|
if let Err(reason) = repair(opts) {
|
|
report.fatal(&format!("{}", reason));
|
|
process::exit(1);
|
|
}
|
|
}
|