1use anyhow::Result;
2use clap::{Parser, Subcommand};
3use tonic::transport::Channel;
4
5use krata::events::EventStream;
6use krata::v1::control::control_service_client::ControlServiceClient;
7
8use crate::cli::zone::attach::ZoneAttachCommand;
9use crate::cli::zone::destroy::ZoneDestroyCommand;
10use crate::cli::zone::exec::ZoneExecCommand;
11use crate::cli::zone::launch::ZoneLaunchCommand;
12use crate::cli::zone::list::ZoneListCommand;
13use crate::cli::zone::logs::ZoneLogsCommand;
14use crate::cli::zone::metrics::ZoneMetricsCommand;
15use crate::cli::zone::resolve::ZoneResolveCommand;
16use crate::cli::zone::top::ZoneTopCommand;
17use crate::cli::zone::update_resources::ZoneUpdateResourcesCommand;
18use crate::cli::zone::watch::ZoneWatchCommand;
19
20pub mod attach;
21pub mod destroy;
22pub mod exec;
23pub mod launch;
24pub mod list;
25pub mod logs;
26pub mod metrics;
27pub mod resolve;
28pub mod top;
29pub mod update_resources;
30pub mod watch;
31
32#[derive(Parser)]
33#[command(about = "Manage the zones on the isolation engine")]
34pub struct ZoneCommand {
35 #[command(subcommand)]
36 subcommand: ZoneCommands,
37}
38
39impl ZoneCommand {
40 pub async fn run(
41 self,
42 client: ControlServiceClient<Channel>,
43 events: EventStream,
44 ) -> Result<()> {
45 self.subcommand.run(client, events).await
46 }
47}
48
49#[allow(clippy::large_enum_variant)]
50#[derive(Subcommand)]
51pub enum ZoneCommands {
52 Attach(ZoneAttachCommand),
53 List(ZoneListCommand),
54 Launch(ZoneLaunchCommand),
55 Destroy(ZoneDestroyCommand),
56 Exec(ZoneExecCommand),
57 Logs(ZoneLogsCommand),
58 Metrics(ZoneMetricsCommand),
59 Resolve(ZoneResolveCommand),
60 Top(ZoneTopCommand),
61 Watch(ZoneWatchCommand),
62 UpdateResources(ZoneUpdateResourcesCommand),
63}
64
65impl ZoneCommands {
66 pub async fn run(
67 self,
68 client: ControlServiceClient<Channel>,
69 events: EventStream,
70 ) -> Result<()> {
71 match self {
72 ZoneCommands::Launch(launch) => launch.run(client, events).await,
73
74 ZoneCommands::Destroy(destroy) => destroy.run(client, events).await,
75
76 ZoneCommands::Attach(attach) => attach.run(client, events).await,
77
78 ZoneCommands::Logs(logs) => logs.run(client, events).await,
79
80 ZoneCommands::List(list) => list.run(client, events).await,
81
82 ZoneCommands::Watch(watch) => watch.run(events).await,
83
84 ZoneCommands::Resolve(resolve) => resolve.run(client).await,
85
86 ZoneCommands::Metrics(metrics) => metrics.run(client, events).await,
87
88 ZoneCommands::Top(top) => top.run(client, events).await,
89
90 ZoneCommands::Exec(exec) => exec.run(client).await,
91
92 ZoneCommands::UpdateResources(update_resources) => update_resources.run(client).await,
93 }
94 }
95}