Skip to main content

driver_tools/subcommands/list_hosts/
mod.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub 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        /* exact_match= */ 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    for (koid, drivers) in driver_hosts {
38        if termion::is_tty(&std::io::stdout()) {
39            println!("Driver Host: {}", koid);
40            for driver in drivers {
41                println!("{:>4}{}", "", driver);
42            }
43            println!("");
44        } else {
45            for driver in drivers {
46                println!("Driver Host: {:<6}{}", koid, driver);
47            }
48        }
49    }
50    Ok(())
51}