From df92792446cdb856b4cb1ee9a43486aba1d89178 Mon Sep 17 00:00:00 2001 From: trkelly23 Date: Mon, 13 Nov 2023 08:12:56 -0500 Subject: [PATCH] feat: add icmp command shortcut (#649) --- src/config.rs | 8 ++++---- src/config/cmd.rs | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index f813036e..5227accb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -435,10 +435,10 @@ impl TryFrom<(Args, &Platform)> for TrippyConfig { constants::DEFAULT_REPORT_CYCLES, ); let geoip_mmdb_file = cfg_layer_opt(args.geoip_mmdb_file, cfg_file_tui.geoip_mmdb_file); - let protocol = match (args.udp, args.tcp, protocol) { - (false, false, Protocol::Icmp) => TracerProtocol::Icmp, - (false, false, Protocol::Udp) | (true, _, _) => TracerProtocol::Udp, - (false, false, Protocol::Tcp) | (_, true, _) => TracerProtocol::Tcp, + let protocol = match (args.udp, args.tcp, args.icmp, protocol) { + (false, false, false, Protocol::Udp) | (true, _, _, _) => TracerProtocol::Udp, + (false, false, false, Protocol::Tcp) | (_, true, _, _) => TracerProtocol::Tcp, + (false, false, false, Protocol::Icmp) | (_, _, true, _) => TracerProtocol::Icmp, }; let read_timeout = humantime::parse_duration(&read_timeout)?; let min_round_duration = humantime::parse_duration(&min_round_duration)?; diff --git a/src/config/cmd.rs b/src/config/cmd.rs index 0f2c859b..8a2f2b21 100644 --- a/src/config/cmd.rs +++ b/src/config/cmd.rs @@ -34,13 +34,32 @@ pub struct Args { pub protocol: Option, /// Trace using the UDP protocol - #[arg(long, conflicts_with = "protocol", conflicts_with = "tcp")] + #[arg( + long, + conflicts_with = "protocol", + conflicts_with = "tcp", + conflicts_with = "icmp" + )] pub udp: bool, /// Trace using the TCP protocol - #[arg(long, conflicts_with = "protocol", conflicts_with = "udp")] + #[arg( + long, + conflicts_with = "protocol", + conflicts_with = "udp", + conflicts_with = "icmp" + )] pub tcp: bool, + /// Trace using the ICMP protocol + #[arg( + long, + conflicts_with = "protocol", + conflicts_with = "udp", + conflicts_with = "tcp" + )] + pub icmp: bool, + /// Use IPv4 only #[arg(short = '4', long, conflicts_with = "ipv6")] pub ipv4: bool,