diff options
| author | diogo464 <[email protected]> | 2025-08-02 10:15:08 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-02 10:15:08 +0100 |
| commit | c7edd27527b553589939b897283454e191a40a00 (patch) | |
| tree | 8a9960c6fa43f50975cd6b11c9bef711e99ee037 /src | |
| parent | b0057110f1fe56c726c1d108c90d1275510a794b (diff) | |
added --interleave flag to oar-p2p net show
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 4fd002a..31f860b 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -125,6 +125,9 @@ struct NetDownArgs { | |||
| 125 | struct NetShowArgs { | 125 | struct NetShowArgs { |
| 126 | #[clap(flatten)] | 126 | #[clap(flatten)] |
| 127 | common: Common, | 127 | common: Common, |
| 128 | |||
| 129 | #[clap(long)] | ||
| 130 | interleave: bool, | ||
| 128 | } | 131 | } |
| 129 | 132 | ||
| 130 | #[derive(Debug, Args)] | 133 | #[derive(Debug, Args)] |
| @@ -265,8 +268,26 @@ async fn cmd_net_show(args: NetShowArgs) -> Result<()> { | |||
| 265 | } | 268 | } |
| 266 | } | 269 | } |
| 267 | addresses.sort(); | 270 | addresses.sort(); |
| 268 | for (machine, addr) in addresses { | 271 | if !args.interleave { |
| 269 | println!("{machine} {addr}"); | 272 | for (machine, addr) in addresses { |
| 273 | println!("{machine} {addr}"); | ||
| 274 | } | ||
| 275 | } else { | ||
| 276 | let mut addrs_per_machine: HashMap<Machine, Vec<Ipv4Addr>> = Default::default(); | ||
| 277 | for (machine, addr) in addresses { | ||
| 278 | addrs_per_machine.entry(machine).or_default().push(addr); | ||
| 279 | } | ||
| 280 | while !addrs_per_machine.is_empty() { | ||
| 281 | for machine in &machines { | ||
| 282 | if let Some(addrs) = addrs_per_machine.get_mut(machine) { | ||
| 283 | if let Some(addr) = addrs.pop() { | ||
| 284 | println!("{machine} {addr}"); | ||
| 285 | } else { | ||
| 286 | addrs_per_machine.remove(machine); | ||
| 287 | } | ||
| 288 | }; | ||
| 289 | } | ||
| 290 | } | ||
| 270 | } | 291 | } |
| 271 | Ok(()) | 292 | Ok(()) |
| 272 | } | 293 | } |
