update clap to v3: log-analyzer

This commit is contained in:
klykov 2022-03-07 17:19:31 +01:00 committed by kirill lykov
parent 12e24a90a0
commit 300c50798f
2 changed files with 19 additions and 19 deletions

View File

@ -11,7 +11,7 @@ publish = false
[dependencies] [dependencies]
byte-unit = "4.0.14" byte-unit = "4.0.14"
clap = "2.33.1" clap = { version = "3.1.5", features = ["cargo"] }
serde = "1.0.136" serde = "1.0.136"
serde_json = "1.0.79" serde_json = "1.0.79"
solana-logger = { path = "../logger", version = "=1.11.0" } solana-logger = { path = "../logger", version = "=1.11.0" }

View File

@ -3,7 +3,7 @@ extern crate byte_unit;
use { use {
byte_unit::Byte, byte_unit::Byte,
clap::{crate_description, crate_name, value_t_or_exit, App, Arg, ArgMatches, SubCommand}, clap::{crate_description, crate_name, Arg, ArgMatches, Command},
serde::{Deserialize, Serialize}, serde::{Deserialize, Serialize},
std::{collections::HashMap, fs, ops::Sub, path::PathBuf}, std::{collections::HashMap, fs, ops::Sub, path::PathBuf},
}; };
@ -97,7 +97,7 @@ fn map_ip_address(mappings: &[IpAddrMapping], target: String) -> String {
fn process_iftop_logs(matches: &ArgMatches) { fn process_iftop_logs(matches: &ArgMatches) {
let mut map_list: Vec<IpAddrMapping> = vec![]; let mut map_list: Vec<IpAddrMapping> = vec![];
if let ("map-IP", Some(args_matches)) = matches.subcommand() { if let Some(("map-IP", args_matches)) = matches.subcommand() {
let mut list = args_matches let mut list = args_matches
.value_of("list") .value_of("list")
.expect("Missing list of IP address mappings") .expect("Missing list of IP address mappings")
@ -112,7 +112,7 @@ fn process_iftop_logs(matches: &ArgMatches) {
map_list = serde_json::from_str(&list).expect("Failed to parse IP address mapping list"); map_list = serde_json::from_str(&list).expect("Failed to parse IP address mapping list");
}; };
let log_path = PathBuf::from(value_t_or_exit!(matches, "file", String)); let log_path = PathBuf::from(matches.value_of_t_or_exit::<String>("file"));
let mut log = fs::read_to_string(&log_path).expect("Unable to read log file"); let mut log = fs::read_to_string(&log_path).expect("Unable to read log file");
log.insert(0, '['); log.insert(0, '[');
let terminate_at = log.rfind('}').expect("Didn't find a terminating '}'") + 1; let terminate_at = log.rfind('}').expect("Didn't find a terminating '}'") + 1;
@ -148,7 +148,7 @@ fn process_iftop_logs(matches: &ArgMatches) {
} }
fn analyze_logs(matches: &ArgMatches) { fn analyze_logs(matches: &ArgMatches) {
let dir_path = PathBuf::from(value_t_or_exit!(matches, "folder", String)); let dir_path = PathBuf::from(matches.value_of_t_or_exit::<String>("folder"));
assert!( assert!(
dir_path.is_dir(), dir_path.is_dir(),
"Need a folder that contains all log files" "Need a folder that contains all log files"
@ -196,26 +196,26 @@ fn analyze_logs(matches: &ArgMatches) {
fn main() { fn main() {
solana_logger::setup(); solana_logger::setup();
let matches = App::new(crate_name!()) let matches = Command::new(crate_name!())
.about(crate_description!()) .about(crate_description!())
.version(solana_version::version!()) .version(solana_version::version!())
.subcommand( .subcommand(
SubCommand::with_name("iftop") Command::new("iftop")
.about("Process iftop log file") .about("Process iftop log file")
.arg( .arg(
Arg::with_name("file") Arg::new("file")
.short("f") .short('f')
.long("file") .long("file")
.value_name("iftop log file") .value_name("iftop log file")
.takes_value(true) .takes_value(true)
.help("Location of the log file generated by iftop"), .help("Location of the log file generated by iftop"),
) )
.subcommand( .subcommand(
SubCommand::with_name("map-IP") Command::new("map-IP")
.about("Map private IP to public IP Address") .about("Map private IP to public IP Address")
.arg( .arg(
Arg::with_name("list") Arg::new("list")
.short("l") .short('l')
.long("list") .long("list")
.value_name("JSON string") .value_name("JSON string")
.takes_value(true) .takes_value(true)
@ -225,19 +225,19 @@ fn main() {
), ),
) )
.subcommand( .subcommand(
SubCommand::with_name("analyze") Command::new("analyze")
.about("Compare processed network log files") .about("Compare processed network log files")
.arg( .arg(
Arg::with_name("folder") Arg::new("folder")
.short("f") .short('f')
.long("folder") .long("folder")
.value_name("DIR") .value_name("DIR")
.takes_value(true) .takes_value(true)
.help("Location of processed log files"), .help("Location of processed log files"),
) )
.arg( .arg(
Arg::with_name("all") Arg::new("all")
.short("a") .short('a')
.long("all") .long("all")
.takes_value(false) .takes_value(false)
.help("List all differences"), .help("List all differences"),
@ -246,8 +246,8 @@ fn main() {
.get_matches(); .get_matches();
match matches.subcommand() { match matches.subcommand() {
("iftop", Some(args_matches)) => process_iftop_logs(args_matches), Some(("iftop", args_matches)) => process_iftop_logs(args_matches),
("analyze", Some(args_matches)) => analyze_logs(args_matches), Some(("analyze", args_matches)) => analyze_logs(args_matches),
_ => {} _ => {}
}; };
} }