blkar_lib/
cli_show.rs

1use show_core::Param;
2use show_core;
3use std::str::FromStr;
4
5use json_printer::BracketType;
6
7use clap::*;
8use cli_utils::*;
9
10pub fn sub_command<'a, 'b>() -> App<'a, 'b> {
11    SubCommand::with_name("show")
12        .about("Search for and print metadata in file
13
14===== IMPORTANT =====
15Please note that this is the last version of this software to be released under the name rsbx,
16future releases will be published under the name blkar. See project repo for details.
17=====================")
18        .arg(in_file_arg()
19             .help("SBX container to search for metadata"))
20        .arg(Arg::with_name("show_all")
21             .long("show-all")
22             .help("Show all metadata (by default only shows the first one)"))
23        .arg(force_misalign_arg())
24        .arg(pr_verbosity_level_arg())
25        .arg(from_byte_arg()
26             .help("Start from byte FROM-BYTE. The position is automatically rounded
27down to the closest multiple of 128 bytes. If this option is not
28specified, defaults to the start of file. Negative values are rejected.
29If FROM-BYTE exceeds the largest possible position (file size - 1),
30then it will be treated as (file size - 1). The rounding procedure
31is applied after all auto-adjustments."))
32        .arg(to_byte_arg())
33        .arg(guess_burst_arg())
34        .arg(json_arg())
35}
36
37pub fn show<'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 from_pos = get_from_pos!(matches, json_printer);
47    let to_pos   = get_to_pos!(matches, json_printer);
48
49    let param = Param::new(matches.is_present("show_all"),
50                           matches.is_present("guess_burst"),
51                           matches.is_present("force_misalign"),
52                           &json_printer,
53                           from_pos,
54                           to_pos,
55                           in_file,
56                           pr_verbosity_level);
57    match show_core::show_file(&param) {
58        Ok(s)  => exit_with_msg!(ok json_printer => "{}", s),
59        Err(e) => exit_with_msg!(op json_printer => "{}", e)
60    }
61}