update clap to v3: log-analyzer
This commit is contained in:
parent
12e24a90a0
commit
300c50798f
@ -11,7 +11,7 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
byte-unit = "4.0.14"
|
||||
clap = "2.33.1"
|
||||
clap = { version = "3.1.5", features = ["cargo"] }
|
||||
serde = "1.0.136"
|
||||
serde_json = "1.0.79"
|
||||
solana-logger = { path = "../logger", version = "=1.11.0" }
|
||||
|
@ -3,7 +3,7 @@ extern crate byte_unit;
|
||||
|
||||
use {
|
||||
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},
|
||||
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) {
|
||||
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
|
||||
.value_of("list")
|
||||
.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");
|
||||
};
|
||||
|
||||
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");
|
||||
log.insert(0, '[');
|
||||
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) {
|
||||
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!(
|
||||
dir_path.is_dir(),
|
||||
"Need a folder that contains all log files"
|
||||
@ -196,26 +196,26 @@ fn analyze_logs(matches: &ArgMatches) {
|
||||
fn main() {
|
||||
solana_logger::setup();
|
||||
|
||||
let matches = App::new(crate_name!())
|
||||
let matches = Command::new(crate_name!())
|
||||
.about(crate_description!())
|
||||
.version(solana_version::version!())
|
||||
.subcommand(
|
||||
SubCommand::with_name("iftop")
|
||||
Command::new("iftop")
|
||||
.about("Process iftop log file")
|
||||
.arg(
|
||||
Arg::with_name("file")
|
||||
.short("f")
|
||||
Arg::new("file")
|
||||
.short('f')
|
||||
.long("file")
|
||||
.value_name("iftop log file")
|
||||
.takes_value(true)
|
||||
.help("Location of the log file generated by iftop"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("map-IP")
|
||||
Command::new("map-IP")
|
||||
.about("Map private IP to public IP Address")
|
||||
.arg(
|
||||
Arg::with_name("list")
|
||||
.short("l")
|
||||
Arg::new("list")
|
||||
.short('l')
|
||||
.long("list")
|
||||
.value_name("JSON string")
|
||||
.takes_value(true)
|
||||
@ -225,19 +225,19 @@ fn main() {
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("analyze")
|
||||
Command::new("analyze")
|
||||
.about("Compare processed network log files")
|
||||
.arg(
|
||||
Arg::with_name("folder")
|
||||
.short("f")
|
||||
Arg::new("folder")
|
||||
.short('f')
|
||||
.long("folder")
|
||||
.value_name("DIR")
|
||||
.takes_value(true)
|
||||
.help("Location of processed log files"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("all")
|
||||
.short("a")
|
||||
Arg::new("all")
|
||||
.short('a')
|
||||
.long("all")
|
||||
.takes_value(false)
|
||||
.help("List all differences"),
|
||||
@ -246,8 +246,8 @@ fn main() {
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
("iftop", Some(args_matches)) => process_iftop_logs(args_matches),
|
||||
("analyze", Some(args_matches)) => analyze_logs(args_matches),
|
||||
Some(("iftop", args_matches)) => process_iftop_logs(args_matches),
|
||||
Some(("analyze", args_matches)) => analyze_logs(args_matches),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user