From f64af134247e7c3044db41487ac763ff1b2a9f21 Mon Sep 17 00:00:00 2001 From: fanyang Date: Tue, 18 Aug 2026 20:37:57 +0800 Subject: [PATCH] fix(cli): preserve proxy CIDRs in route output (#2503) --- easytier/src/easytier-cli.rs | 70 ++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/easytier/src/easytier-cli.rs b/easytier/src/easytier-cli.rs index fadc1175..9eef0c47 100644 --- a/easytier/src/easytier-cli.rs +++ b/easytier/src/easytier-cli.rs @@ -537,6 +537,17 @@ type LocalBoxFuture<'a, T> = Pin> + 'a> type ForeignNetworkMap = BTreeMap; type GlobalForeignNetworkMap = BTreeMap; +const ROUTE_OPTIONAL_COLUMNS: &[&str] = &["hostname"]; +const ROUTE_DROP_COLUMNS: &[&str] = &[ + "version", + "next_hop_hostname_lat_first", + "next_hop_ipv4_lat_first", + "path_len_lat_first", + "path_latency_lat_first", + "next_hop_hostname", + "next_hop_lat", +]; + fn is_missing_web_client_service(error: &RpcError) -> bool { matches!( error, @@ -569,6 +580,60 @@ mod tests { assert!(!is_missing_web_client_service(&error)); } + + #[test] + fn proxy_cidrs_are_displayed_one_per_line() { + assert_eq!( + format_proxy_cidrs("10.0.0.0/24, 192.168.0.0/16"), + "10.0.0.0/24\n192.168.0.0/16" + ); + assert_eq!(format_proxy_cidrs("10.0.0.0/24"), "10.0.0.0/24"); + assert_eq!(format_proxy_cidrs(""), ""); + } + + #[test] + fn route_column_priority_preserves_proxy_cidrs() { + let headers = [ + "ipv4", + "hostname", + "proxy_cidrs", + "next_hop_ipv4", + "next_hop_hostname", + "next_hop_lat", + "path_len", + "path_latency", + "next_hop_ipv4_lat_first", + "next_hop_hostname_lat_first", + "path_len_lat_first", + "path_latency_lat_first", + "version", + ] + .map(str::to_string); + let col_widths = headers + .iter() + .map(|header| text_width(header)) + .collect::>(); + let drop_indices = header_indices(&headers, ROUTE_DROP_COLUMNS); + + let (active, dropped, total_width) = + select_columns_to_drop(Some(79), &drop_indices, &col_widths); + + let proxy_index = headers + .iter() + .position(|header| header == "proxy_cidrs") + .unwrap(); + assert!(active[proxy_index]); + assert!(!dropped.contains(&proxy_index)); + assert!(total_width <= 79); + } +} + +fn format_proxy_cidrs(value: &str) -> String { + value + .split(',') + .map(str::trim) + .collect::>() + .join("\n") } #[derive(serde::Serialize)] @@ -1707,6 +1772,7 @@ impl<'a> CommandHandler<'a> { struct RouteTableItem { ipv4: String, hostname: String, + #[tabled(display_with = "format_proxy_cidrs")] proxy_cidrs: String, next_hop_ipv4: String, @@ -1833,8 +1899,8 @@ impl<'a> CommandHandler<'a> { print_output( &items, self.output_format, - &["proxy_cidrs", "version"], - &["proxy_cidrs", "version"], + ROUTE_OPTIONAL_COLUMNS, + ROUTE_DROP_COLUMNS, self.no_trunc, ) })