1use crate::cli_utils::*;
2use crate::json_printer::BracketType;
3use crate::repair_core;
4use crate::repair_core::Param;
5use clap::*;
6
7pub fn sub_command<'a, 'b>() -> App<'a, 'b> {
8 SubCommand::with_name("repair")
9 .about("Repair SBX container")
10 .arg(in_file_arg().help("SBX container to repair"))
11 .arg(pr_verbosity_level_arg())
12 .arg(burst_arg().help(
13 "Burst error resistance level used by the container.
14Use this if the level used by the container is above 1000,
15as blkar will only guess up to 1000. Or use this when blkar
16fails to guess correctly.",
17 ))
18 .arg(
19 verbose_arg()
20 .help("Show reference block info, successes and failures of all required repairs"),
21 )
22 .arg(
23 Arg::with_name("skip_warning")
24 .short("y")
25 .long("skip-warning")
26 .help("Skip warning about in-place automatic repairs"),
27 )
28 .arg(dry_run_arg().help("Only do repairs in memory. The container will not be modified."))
29 .arg(json_arg().help(
30 "Output information in JSON format. Note that blkar does not
31guarantee the JSON data to be well-formed if blkar is interrupted.
32This also implies --skip-warning, and changes progress report text
33(if any) to be in JSON.",
34 ))
35}
36
37pub fn repair<'a>(matches: &ArgMatches<'a>) -> i32 {
38 let json_printer = get_json_printer!(matches);
39
40 json_printer.print_open_bracket(None, BracketType::Curly);
41
42 let in_file = get_in_file!(matches, json_printer);
43
44 let pr_verbosity_level = get_pr_verbosity_level!(matches, json_printer);
45
46 let burst = get_burst_opt!(matches, json_printer);
47
48 if matches.is_present("dry_run") && !json_printer.json_enabled() {
49 print_block!(
50 "Note : This is a dry run only, the container is not modified.";
51 "";
52 );
53 }
54
55 if !matches.is_present("skip_warning")
56 && !matches.is_present("dry_run")
57 && !json_printer.json_enabled()
58 {
59 print_block!(
60 "Warning :";
61 "";
62 " Repair mode modifies the SBX container in-place.";
63 "";
64 " This may cause further damage to the container and prohibit further";
65 " data recovery if incorrect automatic repairs are made.";
66 "";
67 " It is advisable to make a copy of the container and work on the copy";
68 " rather than repairing the original container directly.";
69 "";
70 );
71
72 ask_if_wish_to_continue!();
73 }
74
75 let param = Param::new(
76 in_file,
77 matches.is_present("dry_run"),
78 &json_printer,
79 matches.is_present("verbose"),
80 pr_verbosity_level,
81 burst,
82 );
83 match repair_core::repair_file(¶m) {
84 Ok(Some(s)) => exit_with_msg!(ok json_printer => "{}", s),
85 Ok(None) => exit_with_msg!(ok json_printer => ""),
86 Err(e) => exit_with_msg!(op json_printer => "{}", e),
87 }
88}