rkubectl_app/cli/
command.rs1use tabled::settings::Padding;
2use tabled::settings::Remove;
3use tabled::settings::Style;
4use tabled::settings::location::ByColumnName;
5
6use k8s::ClusterRoleExt;
7use k8s::NamespaceExt;
8use k8s::PolicyRuleExt;
9use k8s::SecretExt;
10
11use super::*;
12
13pub use api_resource::ApiResource;
14pub use api_resource::ApiResources;
15pub use basic::Basic;
16pub use basic::Create;
17pub use basic::CreateResource;
18pub use cluster::ClusterInfo;
19pub use cluster::ClusterManagement;
20pub use cluster::Dump;
21pub use config::Config;
22pub use configmap::ConfigMap;
23pub use delete::Delete;
24pub use get::Get;
25pub use node::Node;
26pub use secret::Secret;
27pub use troubleshoot::Auth;
28pub use troubleshoot::Debug;
29pub use troubleshoot::TroubleshootingDebugging;
30
31mod api_resource;
32mod basic;
33mod cluster;
34mod config;
35mod configmap;
36mod delete;
37mod get;
38mod node;
39mod secret;
40mod troubleshoot;
41
42#[derive(Clone, Debug, Subcommand)]
43pub enum Command {
44 #[command(flatten,
45 )]
47 Basic(Basic),
48
49 #[command(flatten)]
50 Intermediate(Intermediate),
51
52 #[command(flatten)]
53 Deploy(Deploy),
54
55 #[command(flatten)]
56 ClusterManagement(ClusterManagement),
57
58 #[command(flatten)]
59 TroubleshootingDebugging(TroubleshootingDebugging),
60
61 ApiResources(ApiResources),
63
64 ApiVersions,
66
67 #[command(subcommand, visible_alias = "cfg")]
69 Config(Config),
70
71 Features,
73
74 Info,
76
77 #[command(subcommand, visible_aliases = ["no", "nodes"])]
79 Node(Node),
80
81 #[command(subcommand, visible_aliases = ["se", "sec", "secrets"])]
83 Secret(Secret),
84
85 #[command(subcommand, visible_aliases = ["cm", "configmaps"])]
87 ConfigMap(ConfigMap),
88
89 Version,
91}
92
93impl Command {
94 pub async fn exec(self, context: &Context) -> RkResult<()> {
95 context.kubeapi().debug(&self);
96 match self {
97 Self::Basic(basic) => basic.exec(context).await,
98 Self::Intermediate(intermediate) => intermediate.exec(context).await,
99 Self::Deploy(deploy) => deploy.exec(context).await,
100 Self::ClusterManagement(cluster_management) => cluster_management.exec(context).await,
101 Self::TroubleshootingDebugging(tsd) => tsd.exec(context).await,
102 Self::ApiResources(api_resources) => api_resources.exec(context).await,
103 Self::ApiVersions => self.api_versions(context).await,
104 Self::Config(config) => config.exec(context),
105 Self::Features => self.features(context).await,
106 Self::Info => self.info(context).await,
107 Self::Node(node) => node.exec(context).await,
108 Self::Secret(secret) => secret.exec(context).await,
109 Self::ConfigMap(configmap) => configmap.exec(context).await,
110 Self::Version => self.version(context).await,
111 }
112 }
113
114 async fn api_versions(&self, context: &Context) -> RkResult<()> {
115 context
116 .kubeapi()
117 .api_versions()
118 .await?
119 .for_each(|version| context.print_deprecated(version.group_version));
120 Ok(())
121 }
122
123 async fn features(&self, context: &Context) -> RkResult<()> {
124 let features = context.kubeapi().features().await?;
125 context.show(features);
126 Ok(())
127 }
128
129 async fn info(&self, context: &Context) -> RkResult<()> {
130 let info = context.kubeapi().info().await?;
131
132 context.print_deprecated(format!("build date: {}", info.build_date));
133 context.print_deprecated(format!("compiler: {}", info.compiler));
134 context.print_deprecated(format!("compiler: {}", info.compiler));
135 context.print_deprecated(format!("git_commit: {}", info.git_commit));
136 context.print_deprecated(format!("git_tree_state: {}", info.git_tree_state));
137 context.print_deprecated(format!("git_version: {}", info.git_version));
138 context.print_deprecated(format!("go_version: {}", info.go_version));
139 context.print_deprecated(format!("major: {}", info.major));
140 context.print_deprecated(format!("minor: {}", info.minor));
141 context.print_deprecated(format!("platform: {}", info.platform));
142
143 Ok(())
144 }
145
146 async fn version(&self, context: &Context) -> RkResult<()> {
147 let text = context.kubeapi().version().await?;
148 context.print_deprecated(text);
149 Ok(())
150 }
151}
152
153#[derive(Clone, Debug, Subcommand)]
155pub enum Intermediate {
157 Explain,
159 Get(Get),
160 Edit,
162 Delete(Delete),
164}
165
166impl Intermediate {
167 async fn exec(self, context: &Context) -> RkResult<()> {
168 match self {
169 Self::Explain => Err(RkError::todo()),
170 Self::Get(get) => get.exec(context).await,
171 Self::Edit => Err(RkError::todo()),
172 Self::Delete(delete) => delete.exec(context).await,
173 }
174 }
175}
176
177#[derive(Clone, Debug, Subcommand)]
179
180pub enum Deploy {
181 Rollout,
183
184 Scale,
186
187 Autoscale,
189}
190
191impl Deploy {
192 async fn exec(self, context: &Context) -> RkResult<()> {
193 context.not_implemented(&self);
194 match self {
195 Self::Rollout => Err(RkError::todo()),
196 Self::Scale => Err(RkError::todo()),
197 Self::Autoscale => Err(RkError::todo()),
198 }
199 }
200}
201
202