2024-04-15 17:24:14 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use clap::{Parser, ValueEnum};
|
|
|
|
use krata::v1::{
|
2024-04-16 08:53:44 +00:00
|
|
|
common::OciImageFormat,
|
2024-04-15 17:24:14 +00:00
|
|
|
control::{control_service_client::ControlServiceClient, PullImageRequest},
|
|
|
|
};
|
|
|
|
|
|
|
|
use tonic::transport::Channel;
|
|
|
|
|
|
|
|
use crate::pull::pull_interactive_progress;
|
|
|
|
|
|
|
|
#[derive(ValueEnum, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum PullImageFormat {
|
|
|
|
Squashfs,
|
|
|
|
Erofs,
|
2024-04-16 08:53:44 +00:00
|
|
|
Tar,
|
2024-04-15 17:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(about = "Pull an image into the cache")]
|
|
|
|
pub struct PullCommand {
|
|
|
|
#[arg(help = "Image name")]
|
|
|
|
image: String,
|
|
|
|
#[arg(short = 's', long, default_value = "squashfs", help = "Image format")]
|
|
|
|
image_format: PullImageFormat,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PullCommand {
|
|
|
|
pub async fn run(self, mut client: ControlServiceClient<Channel>) -> Result<()> {
|
|
|
|
let response = client
|
|
|
|
.pull_image(PullImageRequest {
|
|
|
|
image: self.image.clone(),
|
|
|
|
format: match self.image_format {
|
2024-04-16 08:53:44 +00:00
|
|
|
PullImageFormat::Squashfs => OciImageFormat::Squashfs.into(),
|
|
|
|
PullImageFormat::Erofs => OciImageFormat::Erofs.into(),
|
|
|
|
PullImageFormat::Tar => OciImageFormat::Tar.into(),
|
2024-04-15 17:24:14 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
let reply = pull_interactive_progress(response.into_inner()).await?;
|
|
|
|
println!("{}", reply.digest);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|