mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-13 17:35:37 +00:00
cli: sort peers by IPv4 and hostname (#1191)
* cli: sort entries by IPv4 and hostname Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -545,6 +545,18 @@ impl CommandHandler<'_> {
|
||||
items.push(p.into());
|
||||
}
|
||||
|
||||
// Sort items by ipv4 (using IpAddr for proper numeric comparison) first, then by hostname
|
||||
items.sort_by(|a, b| {
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::str::FromStr;
|
||||
let a_ip = IpAddr::from_str(&a.ipv4).unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED));
|
||||
let b_ip = IpAddr::from_str(&b.ipv4).unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED));
|
||||
match a_ip.cmp(&b_ip) {
|
||||
std::cmp::Ordering::Equal => a.hostname.cmp(&b.hostname),
|
||||
other => other,
|
||||
}
|
||||
});
|
||||
|
||||
print_output(&items, self.output_format)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user