driver_tools/subcommands/list_hosts/
mod.rs1pub mod args;
6
7use anyhow::Result;
8use args::ListHostsCommand;
9use flex_fuchsia_driver_development as fdd;
10#[cfg(feature = "fdomain")]
11use fuchsia_driver_dev_fdomain as fuchsia_driver_dev;
12use std::collections::{BTreeMap, BTreeSet};
13
14pub async fn list_hosts(
15 _cmd: ListHostsCommand,
16 driver_development_proxy: fdd::ManagerProxy,
17) -> Result<()> {
18 println!("This command is deprecated, please use \"driver host list\" in the future.");
19
20 let device_info = fuchsia_driver_dev::get_device_info(
21 &driver_development_proxy,
22 &[],
23 false,
24 )
25 .await?;
26
27 let mut driver_hosts = BTreeMap::new();
28
29 for device in device_info {
30 if let Some(koid) = device.driver_host_koid {
31 if let Some(url) = device.bound_driver_url {
32 driver_hosts.entry(koid).or_insert(BTreeSet::new()).insert(url);
33 }
34 }
35 }
36
37 let max_koid_len =
38 driver_hosts.keys().map(|koid| koid.to_string().len()).max().unwrap_or(0).max(5);
39
40 for (koid, drivers) in driver_hosts {
41 if termion::is_tty(&std::io::stdout()) {
42 println!("Driver Host: {}", koid);
43 for driver in drivers {
44 println!("{:>4}{}", "", driver);
45 }
46 println!("");
47 } else {
48 for driver in drivers {
49 println!("Driver Host: {:<width$} {}", koid, driver, width = max_koid_len);
50 }
51 }
52 }
53 Ok(())
54}