use crate::cli::formats::OutputFormat;
use clap::Subcommand;
use std::path::PathBuf;
#[derive(Subcommand, Debug)]
pub enum Commands {
Get {
#[command(subcommand)]
resource: GetImages,
},
}
#[derive(Subcommand, Debug)]
pub enum GetImages {
Images {
#[arg(
short,
long,
default_value = "default",
conflicts_with = "all_namespaces"
)]
namespace: String,
#[arg(short = 'N', long = "node", conflicts_with = "all_namespaces")]
node: Option<String>,
#[arg(short, long)]
pod: Option<String>,
#[arg(short = 'R', long = "registry")]
registry: Option<String>,
#[arg(short = 'A', long = "all-namespaces", conflicts_with = "namespace")]
all_namespaces: bool,
#[arg(short = 'o', long = "output", default_value = "normal")]
output: OutputFormat,
#[arg(long = "kubeconfig")]
kubeconfig: Option<PathBuf>,
},
Registries {
#[arg(
short,
long,
default_value = "default",
conflicts_with = "all_namespaces"
)]
namespace: String,
#[arg(short = 'A', long = "all-namespaces", conflicts_with = "namespace")]
all_namespaces: bool,
#[arg(short = 'o', long = "output", default_value = "normal")]
output: OutputFormat,
#[arg(long = "kubeconfig")]
kubeconfig: Option<PathBuf>,
},
}
impl GetImages {
pub fn get_kubeconfig_path(&self) -> Option<PathBuf> {
match self {
GetImages::Images { kubeconfig, .. } | GetImages::Registries { kubeconfig, .. } => {
kubeconfig.clone()
}
}
}
pub fn get_namespace(&self) -> &str {
match self {
GetImages::Images { namespace, .. } | GetImages::Registries { namespace, .. } => {
namespace
}
}
}
pub fn is_all_namespaces(&self) -> bool {
match self {
GetImages::Images { all_namespaces, .. }
| GetImages::Registries { all_namespaces, .. } => *all_namespaces,
}
}
}