35 lines
799 B
Rust
35 lines
799 B
Rust
use std::fs;
|
|
|
|
use crate::registry::{registry_base_dir, validate_image_name};
|
|
use anyhow::Context;
|
|
use clap::Subcommand;
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
pub enum ImageCmd {
|
|
Ls,
|
|
Rm { image: String },
|
|
}
|
|
|
|
pub fn run(cmd: ImageCmd) -> anyhow::Result<()> {
|
|
match cmd {
|
|
ImageCmd::Ls => ls(),
|
|
ImageCmd::Rm { image } => rm(&image),
|
|
}
|
|
}
|
|
|
|
fn rm(image: &str) -> Result<(), anyhow::Error> {
|
|
validate_image_name(image)?;
|
|
let image_dir = registry_base_dir()?.join(image);
|
|
fs::remove_dir_all(image_dir).context("Failed to remove image dir")?;
|
|
Ok(())
|
|
}
|
|
|
|
fn ls() -> anyhow::Result<()> {
|
|
let dir = fs::read_dir(registry_base_dir()?)?;
|
|
for entry in dir {
|
|
let entry = entry?.file_name();
|
|
println!(" {}", entry.to_string_lossy());
|
|
}
|
|
Ok(())
|
|
}
|