Skip to main content

driver_tools/
args.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
5use super::subcommands::composite::args::CompositeCommand;
6use super::subcommands::disable::args::DisableCommand;
7use super::subcommands::doctor::args::DoctorCommand;
8use super::subcommands::dump::args::DumpCommand;
9use super::subcommands::enable::args::EnableCommand;
10use super::subcommands::health_check::args::HealthCheckCommand;
11use super::subcommands::host::args::HostCommand;
12use super::subcommands::list::args::ListCommand;
13use super::subcommands::list_composite_node_specs::args::ListCompositeNodeSpecsCommand;
14use super::subcommands::list_composites::args::ListCompositesCommand;
15use super::subcommands::list_devices::args::ListDevicesCommand;
16use super::subcommands::list_hosts::args::ListHostsCommand;
17use super::subcommands::node::args::NodeCommand;
18use super::subcommands::register::args::RegisterCommand;
19use super::subcommands::restart::args::RestartCommand;
20use super::subcommands::show::args::ShowCommand;
21use super::subcommands::test_node::args::TestNodeCommand;
22use argh::{ArgsInfo, FromArgs};
23
24#[derive(Debug, PartialEq)]
25pub struct Boxed<T>(pub Box<T>);
26
27impl<T: argh::FromArgs> argh::FromArgs for Boxed<T> {
28    fn from_args(command_name: &[&str], args: &[&str]) -> Result<Self, argh::EarlyExit> {
29        T::from_args(command_name, args).map(|t| Boxed(Box::new(t)))
30    }
31    fn redact_arg_values(
32        command_name: &[&str],
33        args: &[&str],
34    ) -> Result<Vec<String>, argh::EarlyExit> {
35        T::redact_arg_values(command_name, args)
36    }
37}
38
39impl<T: argh::SubCommand> argh::SubCommand for Boxed<T> {
40    const COMMAND: &'static argh::CommandInfo = T::COMMAND;
41}
42
43impl<T: argh::ArgsInfo> argh::ArgsInfo for Boxed<T> {
44    fn get_args_info() -> argh::CommandInfoWithArgs {
45        T::get_args_info()
46    }
47}
48
49#[cfg(not(target_os = "fuchsia"))]
50use static_checks_lib::args::StaticChecksCommand;
51
52pub type BoxedDisableCommand = Boxed<DisableCommand>;
53pub type BoxedEnableCommand = Boxed<EnableCommand>;
54pub type BoxedDoctorCommand = Boxed<DoctorCommand>;
55pub type BoxedDumpCommand = Boxed<DumpCommand>;
56pub type BoxedListCommand = Boxed<ListCommand>;
57pub type BoxedListCompositesCommand = Boxed<ListCompositesCommand>;
58pub type BoxedListDevicesCommand = Boxed<ListDevicesCommand>;
59pub type BoxedListHostsCommand = Boxed<ListHostsCommand>;
60pub type BoxedListCompositeNodeSpecsCommand = Boxed<ListCompositeNodeSpecsCommand>;
61pub type BoxedRegisterCommand = Boxed<RegisterCommand>;
62pub type BoxedRestartCommand = Boxed<RestartCommand>;
63pub type BoxedShowCommand = Boxed<ShowCommand>;
64pub type BoxedTestNodeCommand = Boxed<TestNodeCommand>;
65pub type BoxedNodeCommand = Boxed<NodeCommand>;
66pub type BoxedHostCommand = Boxed<HostCommand>;
67pub type BoxedCompositeCommand = Boxed<CompositeCommand>;
68pub type BoxedHealthCheckCommand = Boxed<HealthCheckCommand>;
69#[cfg(not(target_os = "fuchsia"))]
70pub type BoxedStaticChecksCommand = Boxed<StaticChecksCommand>;
71
72#[derive(ArgsInfo, FromArgs, Debug, PartialEq)]
73#[argh(name = "driver", description = "Support driver development workflows")]
74pub struct DriverCommand {
75    /// if this exists, the user will be prompted for a component to select.
76    #[argh(switch, short = 's', long = "select")]
77    pub select: bool,
78
79    #[argh(subcommand)]
80    pub subcommand: DriverSubCommand,
81}
82
83#[cfg(target_os = "fuchsia")]
84#[derive(ArgsInfo, FromArgs, Debug, PartialEq)]
85#[argh(subcommand)]
86pub enum DriverSubCommand {
87    Disable(BoxedDisableCommand),
88    Enable(BoxedEnableCommand),
89    Doctor(BoxedDoctorCommand),
90    Dump(BoxedDumpCommand),
91    List(BoxedListCommand),
92    ListComposites(BoxedListCompositesCommand),
93    ListDevices(BoxedListDevicesCommand),
94    ListHosts(BoxedListHostsCommand),
95    ListCompositeNodeSpecs(BoxedListCompositeNodeSpecsCommand),
96    Register(BoxedRegisterCommand),
97    Restart(BoxedRestartCommand),
98    Show(BoxedShowCommand),
99    TestNode(BoxedTestNodeCommand),
100    // New and improved driver commands.
101    Node(BoxedNodeCommand),
102    Host(BoxedHostCommand),
103    Composite(BoxedCompositeCommand),
104    HealthCheck(BoxedHealthCheckCommand),
105}
106
107#[cfg(not(target_os = "fuchsia"))]
108#[derive(ArgsInfo, FromArgs, Debug, PartialEq)]
109#[argh(subcommand)]
110pub enum DriverSubCommand {
111    Disable(BoxedDisableCommand),
112    Enable(BoxedEnableCommand),
113    Doctor(BoxedDoctorCommand),
114    Dump(BoxedDumpCommand),
115    List(BoxedListCommand),
116    ListComposites(BoxedListCompositesCommand),
117    ListDevices(BoxedListDevicesCommand),
118    ListHosts(BoxedListHostsCommand),
119    ListCompositeNodeSpecs(BoxedListCompositeNodeSpecsCommand),
120    Register(BoxedRegisterCommand),
121    Restart(BoxedRestartCommand),
122    StaticChecks(BoxedStaticChecksCommand),
123    Show(BoxedShowCommand),
124    TestNode(BoxedTestNodeCommand),
125    // New and improved driver commands.
126    Node(BoxedNodeCommand),
127    Host(BoxedHostCommand),
128    Composite(BoxedCompositeCommand),
129    HealthCheck(BoxedHealthCheckCommand),
130}