/
githubmirror
/
thin-provisioning-tools
Обзор
Документация
Войти
/
githubmirror
/
thin-provisioning-tools
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/commands/cache_dump.rs
86 строк
3 KB
Ming-Hung Tsai
[commands] Fix version string compatibility issue with LVM
23 фев 2024, 12:55
23 фев 2024, 12:55
3cb749b
Код
Авторство
О чём код?
extern crate clap; use clap::{Arg, ArgAction}; use std::path::Path; use crate::cache::dump::{dump, CacheDumpOptions}; use crate::commands::engine::*; use crate::commands::utils::*; use crate::commands::Command; use crate::version::*; //------------------------------------------ pub struct CacheDumpCommand; impl CacheDumpCommand { fn cli(&self) -> clap::Command { let cmd = clap::Command::new(self.name()) .next_display_order(None) .version(crate::tools_version!()) .disable_version_flag(true) .about("Dump the cache metadata to stdout in XML format") .arg( Arg::new("REPAIR") .help("Repair the metadata whilst dumping it") .short('r') .long("repair") .action(ArgAction::SetTrue), ) // options .arg( Arg::new("OUTPUT") .help("Specify the output file rather than stdout") .short('o') .long("output") .value_name("FILE"), ) // arguments .arg( Arg::new("INPUT") .help("Specify the input device to dump") .required(true) .index(1), ); engine_args(version_args(cmd)) } } impl<'a> Command<'a> for CacheDumpCommand { fn name(&self) -> &'a str { "cache_dump" } fn run(&self, args: &mut dyn Iterator<Item = std::ffi::OsString>) -> exitcode::ExitCode { let matches = self.cli().get_matches_from(args); display_version(&matches); let input_file = Path::new(matches.get_one::<String>("INPUT").unwrap()); let output_file = matches.get_one::<String>("OUTPUT").map(Path::new); // Create a temporary report just in case these checks // need to report anything. let report = std::sync::Arc::new(crate::report::mk_simple_report()); if let Err(e) = check_input_file(input_file).and_then(check_file_not_tiny) { return to_exit_code::<()>(&report, Err(e)); } let engine_opts = parse_engine_opts(ToolType::Cache, &matches); if engine_opts.is_err() { return to_exit_code(&report, engine_opts); } let engine_opts = engine_opts.unwrap(); let opts = CacheDumpOptions { input: input_file, output: output_file, engine_opts, repair: matches.get_flag("REPAIR"), }; to_exit_code(&report, dump(opts)) } } //------------------------------------------