driver_tools/subcommands/host/
mod.rs

1// Copyright 2025 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
7pub mod subcommands;
8
9use anyhow::{Context, Result};
10use args::{HostCommand, HostSubcommand};
11use fidl_fuchsia_driver_development as fdd;
12use std::io::Write;
13
14pub async fn host(
15    cmd: HostCommand,
16    writer: &mut dyn Write,
17    driver_development_proxy: fdd::ManagerProxy,
18) -> Result<()> {
19    match cmd.subcommand {
20        HostSubcommand::List(subcmd) => {
21            subcommands::list::list(subcmd, writer, driver_development_proxy)
22                .await
23                .context("List subcommand failed")?;
24        }
25        HostSubcommand::Show(subcmd) => {
26            subcommands::show::show(subcmd, writer, driver_development_proxy)
27                .await
28                .context("Show subcommand failed")?;
29        }
30    };
31    Ok(())
32}
33
34pub async fn host_machine(
35    cmd: &HostCommand,
36    driver_development_proxy: &fdd::ManagerProxy,
37) -> Result<Option<serde_json::Value>> {
38    match &cmd.subcommand {
39        HostSubcommand::List(_) => {
40            let hosts = subcommands::list::get_driver_hosts(driver_development_proxy).await?;
41            Ok(Some(serde_json::to_value(&hosts)?))
42        }
43        HostSubcommand::Show(subcmd) => {
44            let details =
45                subcommands::show::get_driver_host_details(subcmd, driver_development_proxy)
46                    .await?;
47            Ok(Some(serde_json::to_value(&details)?))
48        }
49    }
50}