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