use tabled::settings::Padding;
use tabled::settings::Remove;
use tabled::settings::Style;
use tabled::settings::location::ByColumnName;
use k8s::ClusterRoleExt;
use k8s::NamespaceExt;
use k8s::PolicyRuleExt;
use k8s::SecretExt;
use super::*;
pub use api_resource::ApiResource;
pub use api_resource::ApiResources;
pub use basic::Basic;
pub use basic::Create;
pub use basic::CreateResource;
pub use cluster::ClusterInfo;
pub use cluster::ClusterManagement;
pub use cluster::Dump;
pub use config::Config;
pub use configmap::ConfigMap;
pub use delete::Delete;
pub use get::Get;
pub use node::Node;
pub use secret::Secret;
pub use troubleshoot::Auth;
pub use troubleshoot::Debug;
pub use troubleshoot::TroubleshootingDebugging;
mod api_resource;
mod basic;
mod cluster;
mod config;
mod configmap;
mod delete;
mod get;
mod node;
mod secret;
mod troubleshoot;
#[derive(Clone, Debug, Subcommand)]
pub enum Command {
#[command(flatten,
// next_help_heading = "Basic Commands (Beginner)"
)]
Basic(Basic),
#[command(flatten)]
Intermediate(Intermediate),
#[command(flatten)]
Deploy(Deploy),
#[command(flatten)]
ClusterManagement(ClusterManagement),
#[command(flatten)]
TroubleshootingDebugging(TroubleshootingDebugging),
ApiResources(ApiResources),
ApiVersions,
#[command(subcommand, visible_alias = "cfg")]
Config(Config),
Features,
Info,
#[command(subcommand, visible_aliases = ["no", "nodes"])]
Node(Node),
#[command(subcommand, visible_aliases = ["se", "sec", "secrets"])]
Secret(Secret),
#[command(subcommand, visible_aliases = ["cm", "configmaps"])]
ConfigMap(ConfigMap),
Version,
}
impl Command {
pub async fn exec(self, context: &Context) -> RkResult<()> {
context.kubeapi().debug(&self);
match self {
Self::Basic(basic) => basic.exec(context).await,
Self::Intermediate(intermediate) => intermediate.exec(context).await,
Self::Deploy(deploy) => deploy.exec(context).await,
Self::ClusterManagement(cluster_management) => cluster_management.exec(context).await,
Self::TroubleshootingDebugging(tsd) => tsd.exec(context).await,
Self::ApiResources(api_resources) => api_resources.exec(context).await,
Self::ApiVersions => self.api_versions(context).await,
Self::Config(config) => config.exec(context),
Self::Features => self.features(context).await,
Self::Info => self.info(context).await,
Self::Node(node) => node.exec(context).await,
Self::Secret(secret) => secret.exec(context).await,
Self::ConfigMap(configmap) => configmap.exec(context).await,
Self::Version => self.version(context).await,
}
}
async fn api_versions(&self, context: &Context) -> RkResult<()> {
context
.kubeapi()
.api_versions()
.await?
.for_each(|version| context.print_deprecated(version.group_version));
Ok(())
}
async fn features(&self, context: &Context) -> RkResult<()> {
let features = context.kubeapi().features().await?;
context.show(features);
Ok(())
}
async fn info(&self, context: &Context) -> RkResult<()> {
let info = context.kubeapi().info().await?;
context.print_deprecated(format!("build date: {}", info.build_date));
context.print_deprecated(format!("compiler: {}", info.compiler));
context.print_deprecated(format!("compiler: {}", info.compiler));
context.print_deprecated(format!("git_commit: {}", info.git_commit));
context.print_deprecated(format!("git_tree_state: {}", info.git_tree_state));
context.print_deprecated(format!("git_version: {}", info.git_version));
context.print_deprecated(format!("go_version: {}", info.go_version));
context.print_deprecated(format!("major: {}", info.major));
context.print_deprecated(format!("minor: {}", info.minor));
context.print_deprecated(format!("platform: {}", info.platform));
Ok(())
}
async fn version(&self, context: &Context) -> RkResult<()> {
let text = context.kubeapi().version().await?;
context.print_deprecated(text);
Ok(())
}
}
#[derive(Clone, Debug, Subcommand)]
pub enum Intermediate {
Explain,
Get(Get),
Edit,
Delete(Delete),
}
impl Intermediate {
async fn exec(self, context: &Context) -> RkResult<()> {
match self {
Self::Explain => Err(RkError::todo()),
Self::Get(get) => get.exec(context).await,
Self::Edit => Err(RkError::todo()),
Self::Delete(delete) => delete.exec(context).await,
}
}
}
#[derive(Clone, Debug, Subcommand)]
pub enum Deploy {
Rollout,
Scale,
Autoscale,
}
impl Deploy {
async fn exec(self, context: &Context) -> RkResult<()> {
context.not_implemented(&self);
match self {
Self::Rollout => Err(RkError::todo()),
Self::Scale => Err(RkError::todo()),
Self::Autoscale => Err(RkError::todo()),
}
}
}