ocilot 0.2.0

cli and library for interacting with OCI registries
Documentation
use clap::Parser;
use ocilot::error;
use ocilot::index::Index;
use ocilot::models::Platform;
use ocilot::uri::Uri;
use snafu::ResultExt;

use super::context::Ctx;

/// Inspect a manifest from a registry.
#[derive(Parser, Debug)]
#[command(version, about = "Get the manifest of an image", long_about = None)]
pub struct Manifest {
    url: String,
    #[arg(short, long)]
    platform: Option<String>,
    #[arg(short, long)]
    insecure: bool,
}

impl Manifest {
    pub async fn run(&self, _ctx: &Ctx) -> Result<(), error::Error> {
        let mut uri = Uri::new(self.url.as_str()).await?;
        uri.set_secure(!self.insecure);
        let platform: Option<Platform> = self.platform.clone().map(|x| x.parse()).transpose()?;
        let index = Index::fetch(&uri).await?;
        let image = index.fetch_image(&uri, platform).await?;
        println!(
            "{}",
            serde_json::to_string_pretty(&image).context(error::SerializeSnafu)?
        );
        Ok(())
    }
}