Add image ls and image rm commands
This commit is contained in:
1 parent
37f537184c
commit
8b544ab688
3 files changed
+61
-23
No files matched your search
@@ -0,0 +1,34 @@
|
||||
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(())
|
||||
}
|
||||
Reference in new issue
Block a user