1use crate::cli_utils::*;
2use crate::json_printer::BracketType;
3use crate::sbx_specs::SBX_FILE_UID_LEN;
4use crate::show_core;
5use crate::show_core::Param;
6use clap::*;
7
8pub fn sub_command<'a, 'b>() -> App<'a, 'b> {
9 SubCommand::with_name("show")
10 .about("Search for and print metadata in file")
11 .arg(in_file_arg().help("SBX container to search for metadata"))
12 .arg(
13 Arg::with_name("show_all")
14 .long("show-all")
15 .help("Show all metadata (by default only shows the first one)"),
16 )
17 .arg(only_pick_uid_arg())
18 .arg(force_misalign_arg())
19 .arg(pr_verbosity_level_arg())
20 .arg(guess_burst_from_byte_arg())
21 .arg(from_byte_arg().help(FROM_BYTE_ARG_HELP_MSG_SCAN))
22 .arg(to_byte_inc_arg())
23 .arg(to_byte_exc_arg())
24 .arg(guess_burst_arg())
25 .arg(json_arg())
26}
27
28pub fn show<'a>(matches: &ArgMatches<'a>) -> i32 {
29 let json_printer = get_json_printer!(matches);
30
31 json_printer.print_open_bracket(None, BracketType::Curly);
32
33 let in_file = get_in_file!(matches, json_printer);
34
35 let pr_verbosity_level = get_pr_verbosity_level!(matches, json_printer);
36
37 let from_pos = get_from_pos!(matches, json_printer);
38 let to_pos = get_to_pos!(matches, json_printer);
39
40 let guess_burst_from_pos = get_guess_burst_from_pos!(matches, json_printer);
41
42 let mut temp_uid = [0; SBX_FILE_UID_LEN];
43 let uid: Option<&[u8; SBX_FILE_UID_LEN]> = get_uid!(matches, temp_uid, json_printer);
44
45 let param = Param::new(
46 matches.is_present("show_all"),
47 matches.is_present("guess_burst"),
48 guess_burst_from_pos,
49 matches.is_present("force_misalign"),
50 &json_printer,
51 from_pos,
52 to_pos,
53 in_file,
54 uid,
55 pr_verbosity_level,
56 );
57 match show_core::show_file(¶m) {
58 Ok(s) => exit_with_msg!(ok json_printer => "{}", s),
59 Err(e) => exit_with_msg!(op json_printer => "{}", e),
60 }
61}