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 fidl_fuchsia_driver_development as fdd;
10use std::collections::{BTreeMap, BTreeSet};
11
12pub async fn list_hosts(
13    _cmd: ListHostsCommand,
14    driver_development_proxy: fdd::ManagerProxy,
15) -> Result<()> {
16    println!("This command is deprecated, please use \"driver host list\" in the future.");
17
18    let device_info = fuchsia_driver_dev::get_device_info(
19        &driver_development_proxy,
20        &[],
21        /* exact_match= */ false,
22    )
23    .await?;
24
25    let mut driver_hosts = BTreeMap::new();
26
27    for device in device_info {
28        if let Some(koid) = device.driver_host_koid {
29            if let Some(url) = device.bound_driver_url {
30                driver_hosts.entry(koid).or_insert(BTreeSet::new()).insert(url);
31            }
32        }
33    }
34
35    for (koid, drivers) in driver_hosts {
36        if termion::is_tty(&std::io::stdout()) {
37            println!("Driver Host: {}", koid);
38            for driver in drivers {
39                println!("{:>4}{}", "", driver);
40            }
41            println!("");
42        } else {
43            for driver in drivers {
44                println!("Driver Host: {:<6}{}", koid, driver);
45            }
46        }
47    }
48    Ok(())
49}